VB.NET 画图工具代码

适于VB.NET编程使用,有基本的一些功能就好了,最好图文并茂。不能有错。

Imports System
Imports System.IO
Public Class Form2
Private mBmpBuffer As Bitmap
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
mBmpBuffer = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height, Me.PictureBox1.CreateGraphics) Dim g As Graphics = Graphics.FromImage(mBmpBuffer)
Dim i As Integer
Dim aa(3, 1) As Single
Dim stra() As String
Try
Dim sr As StreamReader = New StreamReader("D:\模型相关\modeldesign\modelpaint\data.csv")
Dim line As String
Do
line = sr.ReadLine() i = i + 1
If i > 1 Then
stra = Split(line, ";")
aa(i - 2, 0) = Val(stra(0))
aa(i - 2, 1) = Val(stra(1))
End If Loop Until line Is Nothing
sr.Close()
Catch ex As Exception End Try Dim ix As Single
Dim iy As Single
Dim temp As Single temp = aa(0, 0)
For i = 0 To 3
If aa(i, 0) > temp Then
temp = aa(i, 0)
End If
Next
ix = temp temp = aa(0, 1)
For i = 0 To 3
If aa(i, 1) > temp Then
temp = aa(i, 1)
End If
Next
iy = temp
'变换坐标
Dim bx As Single
Dim by As Single bx = PictureBox1.Width / ix
by = PictureBox1.Height / iy 'Dim g As Graphics = Me.PictureBox1.CreateGraphics
g.Clear(Color.White)
Dim mypoint(3) As Point
Dim n As Integer = 3
'变换坐标原点
g.TranslateTransform(PictureBox1.Width / 15, PictureBox1.Height * 14 / 15)
'g.ScaleTransform(PictureBox1.Width / ix, PictureBox1.Height / iy) '绘制坐标轴
Dim mypen As New Pen(Color.Black)
Dim sb As New SolidBrush(Color.Black)
'Dim sb1 As Brush = Brushes.Red
Dim mypen1 As New Pen(Color.Blue, 6)
g.DrawLine(mypen, 0, 0, PictureBox1.Width - 40, 0)
g.DrawLine(mypen, 0, 0, 0, 20 - PictureBox1.Height)
For i = 0 To PictureBox1.Width - 40 Step 40
g.DrawLine(mypen, i, 0, i, -10)
g.DrawString(Int(i / 0.9 / bx), New Font("宋体", 8), sb, i - 10, 0)
Next
g.DrawString("C", New Font("宋体", 8), sb, PictureBox1.Width - 50, 0) For i = 40 To PictureBox1.Height - 40 Step 40
g.DrawLine(mypen, 0, -i, 10, -i)
g.DrawString(Int(i / 0.9 / by), New Font("宋体", 8), sb, -20, -i - 10)
Next
g.DrawString("x", New Font("宋体", 8), sb, -10, 20 - PictureBox1.Height)
'mypen.Width = 1
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
For i = 0 To n
mypoint(i).X = aa(i, 0) * bx * 0.9
mypoint(i).Y = -aa(i, 1) * by * 0.9
'g.FillRectangle(sb1, mypoint(i).X, mypoint(i).Y, 3, mypoint(i).Y)
g.DrawLine(mypen1, mypoint(i).X, 0, mypoint(i).X, mypoint(i).Y)
Next '开始画线
'g.DrawCurve(mypen, mypoint)
Me.PictureBox1.Refresh()
End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strFilter As String = "BMP文件(*.bmp)|*.bmp"
Dim pdlg As SaveFileDialog = New SaveFileDialog
pdlg.Title = "地图另存为"
pdlg.Filter = strFilter
pdlg.OverwritePrompt = True
pdlg.ShowDialog() If Not pdlg.FileName.Equals("") Then
If Not (mBmpBuffer Is Nothing) Then
'mBmpBuffer.Save("c:\a.bmp")
mBmpBuffer.Save(pdlg.FileName)
End If End If
End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click End Sub Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If Not (mBmpBuffer Is Nothing) Then
e.Graphics.DrawImage(mBmpBuffer, 0, 0)
End If
End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Clear()
ComboBox1.Items.Add("模型一")
ComboBox1.Items.Add("模型二")
ComboBox1.Items.Add("模型三")
ComboBox1.Text = "模型一"
End Sub
End Class
发表于 @ 2007年10月31日 11:53:00 | 评论( 0 ) | 编辑| 举报| 收藏 旧一篇:SharpMap AjaxMapControl 中 Zoomin/Zoomout 操作时冻结问题 | 新一篇:Windows 窗体控件进行线程安全调用
本文来自CSDN博客,转载请标明出处: http://blog.csdn.net/Chendy/archive/2007/10/31/1859110.aspx
温馨提示:内容为网友见解,仅供参考
无其他回答

vb.net picture 保存图片
Dim wid As Integer = PictureBox1.ClientSize.Width Dim hgt As Integer = PictureBox1.ClientSize.Height Dim bm As New Bitmap(wid, hgt)Dim g As Graphics = Graphics.FromImage(bm)'画图代码,比如下面的直线 g.DrawLine(Pens.Red, 10, 10, 500, 10)'画图代码 PictureBox1.Image = bm...

关于vb.net中绘图并保存图片的问题
Public Class Form1 Dim imageName As String = "C:\\Documents and Settings\\...\\1126.jpg "Dim i As Image = Image.FromFile(imageName)Dim g As Graphics = Graphics.FromImage(i) '此处从背景图创建Greaphics Private Sub ...

VB.net绘图具体如何设置双缓冲
VB.NET画图是不能设置双缓冲的,双缓冲是指窗体,从来没说是针对控件。不用graphic.clear清理重画就不会闪烁。你可以先把容器删了再重新建立一个再去画。简单举例:Graphics g;Pen p;Panel pl;构造函数初始化:p=new Pen(Color.Red,2);pl=panel1;造成闪烁的画法:g=pl.CreateGraphics();g.Clear...

vbnet中chart的问题
隐藏图表左右的空白部分就可以了,你试试添加如下代码:Chart1.ChartAreas("Default").AxisX.IsMarginVisible = false 希望对你有帮助,如还有问题请追问或是Hi

...2010怎么样能画出图表或者说如何能用Excel表格的画图功能 VB.net
Public Class Form3 Protected Sub iniChart() Dim dt As New DataTable '表增加月份、收入、支出三列 dt.Columns.Add("月份") dt.Columns.Add("收入") dt.Columns.Add("支出") Dim dr As DataRow For i As Integer = 1 To 12 '新增行 dr = dt.NewRow...

...2010怎么样能画出图表或者说如何能用Excel表格的画图功能 VB.net
Public Class Form3 Protected Sub iniChart() Dim dt As New DataTable '表增加月份、收入、支出三列 dt.Columns.Add("月份") dt.Columns.Add("收入") dt.Columns.Add("支出") Dim dr As DataRow For i As Integer = 1 To 12 '新增行 dr = dt.NewRow...

求大神指点vb.net 怎么以指定方式打开图片呢?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '建立新的系统进程 Dim process As New System.Diagnostics.Process() If RadioButton1.Checked Then '设置文件名,此处为图片的真实路径+文件名 process.StartInfo.FileName = "c:\\a.bmp" '...

vb.net开发简单的时钟程序??高手救救我!
Hand类的代码:Public MustInherit Class Hand Protected gp As GraphicsPath = New GraphicsPath()Protected gpBase As GraphicsPath = Nothing Protected midX As Integer = 150 ‘默认的窗体 Protected midY As Integer = 150 ‘中心位置 ‘构造器,得到窗体中心位置 Public Sub New(ByVal theForm As ...

vb.net GDI+
就像你画画,画上去如果你要擦掉当然是擦到底色咯。(当然GDI+也可以像你画画一样只擦一部分)GDI+时钟我写过一个VB6的。代码详见我博客。地址显然百度不让贴上= =。所以你可以看下我的资料。你可以模拟层,就是把所有绘制信息都保存起来。你的流程应当是:如果要绘制了,更新绘制信息(可以是数组啥...

AutoCAD.net\/VB.net\/C# 是什么?
AutoCAD有提供.NET的开发工具包(SDK)也就是所谓的AutoCAD.NET,通过它你可以使用.NET语言(VB.NET\/C#)做一个像AutoCAD样的类似功能的程序,大部分要通过菜单操作的都可以通过代码实现。.NET框架核心是CLI语言,这是和机器无关语言,因此.NET支持跨CPU体系结构(x86、ia64、arm)、跨设备(PC、mobile...

相似回答