.net - 如何使用绘制的内容重新绘制图片框?
问题描述
我有一个图片框,可以得到类似这样的一些输出:
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。如何捕捉图像?
解决方案
我需要使用位图而不是从图片框创建图形对象。
完整的描述请看这里:图片消失时如何重新绘制图片框?
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
推荐阅读
- django - 请求对象中每个应用程序的不同用户代理模型
- php - 如何在 php 代码中添加新行/换行符
- android - react-native android app:processReleaseResources FAILED
- javascript - 从两个数组中找到相同的数字
- python - Python Psycopg 执行脚本方法
- go - 在不指定端口的情况下进行 gRPC 路由
- sequelize.js - Sequelize:使用“嵌套”实例创建实例的副本
- javascript - 范围规则 - let 关键字 - TypeScript/JavaScript
- java - ImageIO 读取器错误和问题
- html - Firefox:大型模糊元素的性能缓慢