问题
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