Type of image in project's resources

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

I'm embedding images into the project's resources (eg.
Properties.Resources.SaveImage). At run time I want to extract the image and
save it to disk, but I want to retain the type of the original image (gif,
jpg, etc) and any transparency set in it. How can I do this? I can't seem to
obtain the type of the embedded image resource - the RawFormat property
gives something quite cryptic.
 
You can open the image with a stream, read in the first few bytes and decode
the result. All the image types I know of have a simple header with a few
bytes of identification code at the start such as BM for bitmaps, GIF89A or
GIF47 for some Gifs. Other images such as JPEG have a binary numeric header.

Usually however, you can look at the filename extension and take an educated
guess...



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

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top