我有一个图片框,它的输出与此类似:
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
问题是DrawingImage为NULL。如何捕获图像?
答案 0 :(得分:0)
我需要使用位图而不是从图片框创建图形对象。
有关完整的说明,请在此处查看: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