PictureBox to a file

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.
 
P

Patrick De Ridder

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top