【问题标题】:How can I repaint a picturebox with the drawn on contents?如何使用绘制的内容重新绘制图片框?
【发布时间】:2019-04-05 17:43:59
【问题描述】:

我有一个图片框,可以得到类似这样的输出:

e = New PrintPageEventArgs(PictureBox1.CreateGraphics, New Rectangle(New Point(25, 25), New Size(New Point(825, 1075))), e.PageBounds, e.PageSettings)

'Draw box
e.Graphics.DrawRectangle(Pens.Gray, 20, 30, e.PageBounds.Width - 100, e.PageBounds.Height - 130)

DrawnImage = PictureBox1.Image

我需要在 Paint 事件中更新它:

Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint

    PictureBox1.Image = DrawnImage 

End Sub

问题是 DrawnImage 为 NULL。如何捕捉图像?

【问题讨论】:

    标签: .net


    【解决方案1】:

    我需要使用位图而不是从图片框创建图形对象。

    完整描述请看这里:How do I repaint my picturebox when the picture disappears?

    Dim b As New Bitmap(PictureBox1.Width, PictureBox1.Height)
    
    e = New PrintPageEventArgs(Graphics.GraphicsFromImage(b), New Rectangle(New Point(25, 25), New Size(New Point(825, 1075))), e.PageBounds, e.PageSettings)
    
    'Draw box
    e.Graphics.DrawRectangle(Pens.Gray, 20, 30, e.PageBounds.Width - 100, e.PageBounds.Height - 130)
    
    PictureBox1.Image = b
    

    【讨论】:

      猜你喜欢
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 2013-07-24
      • 1970-01-01
      • 2011-05-22
      • 1970-01-01
      • 2013-05-14
      • 2014-12-19
      相关资源
      最近更新 更多