Save picturebox's image to stream

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I got the error
=================
An unhandled exception of typ
'System.Runtime.InteropServices.ExternalException' occurred i
system.drawing.dl

Additional information: A generic error occurred in GDI+
=================

the code like this

Image aImg = pictrebox1.Image
MemoryStream ms = new MemoryStream()
aImg.Save(ms,aImg.RawFormat)
 
The error probably comes from the fact that the image has no raw format.
save it as a bitmap, tiff or jpeg.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
 
:
I have tried bmp and jpeg, got same error

I tried your code and it worked for me.

Where does your Image come from ?
Have you tried with another picture ?
What happen if you try the same thing in a new project ?
 
Back
Top