【发布时间】:2011-02-07 01:39:18
【问题描述】:
我在 Windows 窗体上有一个图片框。
我执行以下操作以将 PNG 文件加载到其中。
Bitmap bm = (Bitmap)Image.FromFile("Image.PNG", true);
Bitmap tmp;
public Form1() {
InitializeComponent();
this.tmp = new Bitmap(bm.Width, bm.Height);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e) {
e.Graphics.DrawImage(this.bm, new Rectangle(0, 0, tmp.Width, tmp.Height), 0, 0, tmp.Width, tmp.Height, GraphicsUnit.Pixel);
}
但是,我需要在图像上绘制东西,然后再次显示结果。绘制矩形只能通过 Graphics 类来完成。
我需要在图像上绘制所需的矩形,再次使其成为 Image 类的实例并将其保存到 this.bm
我可以添加一个执行this.pictureBox1.Refresh(); 的按钮,强制重新绘制pictureBox,但我不能将Graphics 转换为Image。因此,我无法将编辑保存到this.bm 位图。
这是我的问题,我看不到出路。
【问题讨论】: