vb.net画直线不消失,将图形保存为bmp文件


须创建bitmap,关联到pictureBox1.image上。

再在pictureBox1.image上创建Graphics,再进行作图。


注意,因pictureBox1.image是最初bitmap创建,认是黑色,故,须用fillrectangle把背景刷成白色。


Imports System.Drawing
Imports System.Drawing.drawing2d
Public Class Form1

    Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click
        Dim gr As Graphics
        Dim bp As New Bitmap(PictureBox1.Width,PictureBox1.Height)

        Dim pen1 As New Pen(Color.Red)
        pen1.DashStyle = DashStyle.DashDotDot
        pen1.Width = 2

        PictureBox1.Image = bp

        gr = Graphics.FromImage(PictureBox1.Image)
        gr.FillRectangle(Brushes.White,New Rectangle(0,PictureBox1.Width,PictureBox1.Height))
        gr.DrawLine(pen1,10,70,70)

        PictureBox1.Image.Save("D:\1.bmp",System.Drawing.Imaging.ImageFormat.Bmp)

        gr.dispose()
    End Sub
End Class





相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...