c# save System.Drawing.Graphics to file

社会主义新天地 提交于 2019-12-11 06:21:39

问题


I have a System.Drawing.Graphics took from a picturebox.

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


回答1:


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());



回答2:


Yep, use the Image.Save method on your PictureBox's Image:

pictureBox.Image.Save(fullnameOfYourImage, System.Drawing.Imaging.ImageFormat.Png);



回答3:


Pretty sure you can convert to a Bitmap and save it?

See this article:

Saving System.Drawing.Graphics to a png or bmp



来源:https://stackoverflow.com/questions/11621726/c-sharp-save-system-drawing-graphics-to-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!