Problems with Bitmap.RawFormat

Ok, now I've been trying to work out this problem for hours and hours, and drawn upon support from a handful of knowledgeble people - none of us has been able to figure it out...

The problem is that Bitmap.RawFormat isn't working like it's supposed to - let me explain: I'm trying to store the images using their original encoding/imageformat, and of course assumed RawFormat (type ImageFormat) would do as we are “promised”. At least I assume it is supposed to return a value declared in ImageFormat, but it doesn't. It simply returns an encoded string (would be helpful to know what encoding):
[ImageFormat: b96b3cae-0728-11d3-9d7b-0000f81ef32e]

I expected to see something simple as: Jpeg

I haven't yet tested this with any other image format. - Well if anyone has any kind of input on this, please let me know, as it is driving me nuts. If this is an expected behavior, I suggest the documentation gets updated, or better yet change this to reflect the actual ImageFormat type. In the meantime, I'm gonna have to dig out all the image format specs and create a helper class to read in the format directly from the binary data - yay! not...

[UPDATE: Problem solved - it was not with RawFormat the problem was it seems :/   Rather is was with non-seekable streams :D]

Published Tuesday, March 16, 2004 10:57 PM by Aylar
Filed under:

Comments

# re: Problems with Bitmap.RawFormat

Tuesday, March 16, 2004 8:13 AM by CC

Thanks looks like the GUID of the Jpeg codec (although I could be wrong).

# re: Problems with Bitmap.RawFormat

Tuesday, March 16, 2004 8:13 AM by CC
Thanks? I mean That.

# re: Problems with Bitmap.RawFormat

Tuesday, March 16, 2004 8:39 AM by Thomas Johansen
Of course it is! I don't know why I didn't see that sooner... Hmm, still doesn't explain the issue I am having tho :/

# re: Problems with Bitmap.RawFormat

Tuesday, March 16, 2004 9:27 AM by CC

Reflection? Ugh I know .. horrible ...

# re: Problems with Bitmap.RawFormat

Tuesday, March 16, 2004 9:32 AM by CC
Actually now that I've spent more than 30 seconds thinking about it (and reading the docs) it looks like .Equals() will give you an ugly way of determining which type it is ..

if ( myImageFormat.Equals( ImageFormat.Bmp ) ) {

} else if ....

I did say it was ugly.. I bet ToString() is also over-ridden to return the string [ImageFormat: and then the GUID for that imageformat.

"Equals Overridden. Returns a value that indicates whether the specified object is an ImageFormat object that is equivalent to this ImageFormat object."

# re: Problems with Bitmap.RawFormat

Tuesday, March 16, 2004 9:34 AM by Jim Arnold
Compare the ImageFormat object you get back from RawFormat with ImageFormat.Jpeg. They should be identical. The GUID you're seeing is definitely Jpeg and looking at the code for ImageFormat.ToString(), it really should be returning "Jpeg". Sorry I don't have a real solution.

Jim

# re: Problems with Bitmap.RawFormat

Thursday, January 31, 2008 4:10 AM by James Miles

This is actually a bug in the .NET Framework. Decompile the ImageFormat class & you'll see;

public override string ToString()

{

   if (this == memoryBMP)

   {

       return "MemoryBMP";

   }

   if (this == bmp)

   {

       return "Bmp";

   }

   if (this == emf)

   {

       return "Emf";

   }

   if (this == wmf)

   {

       return "Wmf";

   }

   if (this == gif)

   {

       return "Gif";

   }

   if (this == jpeg)

   {

       return "Jpeg";

   }

   if (this == png)

   {

       return "Png";

   }

   if (this == tiff)

   {

       return "Tiff";

   }

   if (this == exif)

   {

       return "Exif";

   }

   if (this == icon)

   {

       return "Icon";

   }

   return ("[ImageFormat: " + this.guid + "]");

}

All these if statements are wrong, should be;

if (this.Equals(icon))

{

   return "Icon";

}

etc...

# re: Problems with Bitmap.RawFormat

Tuesday, December 16, 2008 4:29 PM by zwierzak

well, i noticed another thing,

While checking wheter file format of an input image equals to "ImageFormat.Jpeg" i get the following:

//-------------------------

code:

if (an_input_image.Image.RawFormat.ToString() == ImageFormat.Jpeg.Guid.ToString()) {...}

the first term gives :

b96b3caa-0728-11d3-9d7b-0000f81ef32e (input image in jpeg format)

the second one:

b96b3cae-0728-11d3-9d7b-0000f81ef32e  (ImageFormat.Jpeg.Guid)

As u may notice there's a one-character difference ...

b96b3caa vs b96b3cae....

The input file is an jpeg image read into a  Bitmap class object and furhter processed through locking it into memory....

I think it might be mistakenly read as a different format or there's just this mistake in the GUID.

When the input file is then saved with its RawFormat...(the first GUID)... it is recognized by image viewers (IrfanView) as .PNG

Leave a Comment

(required) 
(required) 
(optional)
(required)