C#将System.Drawing.Graphics保存到文件 [英] c# save System.Drawing.Graphics to file
本文介绍了C#将System.Drawing.Graphics保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个System.Drawing.Graphics是从一个图片框中拍摄的.
I have a System.Drawing.Graphics took from a picturebox.
基本上,我在存储在图片框中的背景图像上画了一些线 现在我希望保存一个包含背景图像的png,所有内容都在该位置绘制...
basically I draw some lines over a background image stored into the picturebox now I wish save a png that contains the background image and everything is drawn over there...
有没有办法做到这一点? 预先感谢
is there a way to do this? thanks in advance
推荐答案
如果要在Paint事件上绘制这些线条,则需要使用BackgroundImage创建一个BitMap,并使用Bitmap的Graphics调用paint函数,然后调用位图.Save().
If you are drawing these lines on the Paint event then you need to create a BitMap with the BackgroundImage and call your paint function with the Bitmap's Graphics, and then call Bitmap.Save().
Bitmap bmp = new Bitmap(MyPictureBox.BackgroundImage);
var g = Graphics.FromImage(bmp);
MyPictureBox.OnPaint(new System.Windows.Forms.PaintEventArgs(g, bmp.GetBounds());
这篇关于C#将System.Drawing.Graphics保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文