Saving System.Drawing.Graphics to a png or bmp

前端 未结 5 964
不思量自难忘°
不思量自难忘° 2020-12-08 20:15

I have a Graphics object that I\'ve drawn on the screen and I need to save it to a png or bmp file. Graphics doesn\'t seem to support that directly, but it must be possible

5条回答
  •  悲哀的现实
    2020-12-08 21:00

    You are likely drawing either to an image or on a control. If on image use

        Image.Save("myfile.png",ImageFormat.Png)
    

    If drawing on control use Control.DrawToBitmap() and then save the returned image as above.

    Thanks for the correction - I wasn't aware you can draw directly to the screen.

提交回复
热议问题