PictureBox to a file

  • Thread starter Thread starter Samuel
  • Start date Start date
S

Samuel

Hello coders:

How do I save the image painted on a Graphics object into a file?

I get an exception when I try to do:

Image.FromHbitmap(
pictureBox.CreateGraphics().GetHdc()
).Save("C:\location\file.jpg")

The exception is:

An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.drawing.dll

Additional information: A generic error occurred in GDI+.

I'm sure it must be an easy way to save the changes made on a PictureBox.

Thank you. Samuel.
 
Samuel said:
Hello coders:

How do I save the image painted on a Graphics object into a file?

I get an exception when I try to do:

Image.FromHbitmap(
pictureBox.CreateGraphics().GetHdc()
).Save("C:\location\file.jpg")

The exception is:

An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.drawing.dll

Additional information: A generic error occurred in GDI+.

I'm sure it must be an easy way to save the changes made on a PictureBox.

Thank you. Samuel.
That is described by Erik Brown's book "Windows Forms with C#". You can
download the example code from the Manning website www.manning.com.

Patrick.
 
Back
Top