关于vb.net中绘图并保存图片的问题
目标:在窗体form1中用GDI画图,然后点击按钮将form1中的图形保存成图片PrivateSubform1_paint(ByValsenderAsSystem.Obj...
目标:在窗体form1中用GDI画图,然后点击按钮将form1中的图形保存成图片
Private Sub form1_paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics
Dim brush1 As SolidBrush
brush1 = New SolidBrush(Color.Red)
g = Me.CreateGraphics
g.FillRectangle(brush1, 100, 100, 100, 100)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
********************按钮中的代码不会请高手帮忙,也就是将form1中的图形保存成图片
end sub 展开
Private Sub form1_paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics
Dim brush1 As SolidBrush
brush1 = New SolidBrush(Color.Red)
g = Me.CreateGraphics
g.FillRectangle(brush1, 100, 100, 100, 100)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
********************按钮中的代码不会请高手帮忙,也就是将form1中的图形保存成图片
end sub 展开
展开全部
Imports System.Drawing.Imaging
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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'划线
Dim BluePen As New Pen(Color.Blue, 5)
BluePen.DashStyle = Drawing2D.DashStyle.Solid
g.DrawLine(BluePen, 100.0F, 170, 500.0F, 170)
g.Dispose()
PictureBox1.Image = i
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'退出
Me.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'存盘
i.Save( "C:\testimage.jpg ", ImageFormat.Jpeg)
i.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PictureBox1.Image = i
End Sub
End Class
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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'划线
Dim BluePen As New Pen(Color.Blue, 5)
BluePen.DashStyle = Drawing2D.DashStyle.Solid
g.DrawLine(BluePen, 100.0F, 170, 500.0F, 170)
g.Dispose()
PictureBox1.Image = i
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'退出
Me.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'存盘
i.Save( "C:\testimage.jpg ", ImageFormat.Jpeg)
i.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PictureBox1.Image = i
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询