-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Let's get started with a very simple demo:
-
Create a demo console application and referring net 4.6 framework, with the "System.Drawing" namespace added in.
-
Download or create a file of jpg.
-
Now let's import the file directly into the Image and do this following by:
Image img = Image.FromFile("c:\\test.jpg"); Console.WriteLine(img.RawFormat.Equals(ImageFormat.Jpeg));
Now the answer is "True", and the ImageFormat's Guid for "JPEG" is "{b96b3cae-0728-11d3-9d7b-0000f81ef32e}". The same answer is also for "Equals".
HOWEVER in "ToString" method, the expected result should be "Jpeg" as the output. But I didn't see that, and instead the result is:
[ImageFormat: b96b3cae-0728-11d3-9d7b-0000f81ef32e]
Now let's deeply go into the code (to here), the original source code is from: https://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/Advanced/ImageFormat.cs,b96b3cae-0728-11d3-9d7b-0000f81ef32e,references
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: " + guid + "]";
}
Why do we say "this == another type of ImageFormat" without overridding the operator "=="? And from this demo can we make sure that this is a bug and should be fixed?
And what's more——Why not use "if……else if……else……" instead of multiple "if" here?
PS:I didn't find the ImageFormat.cs yet, though I did a full research.