-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug Suspected] ImageFormat's "ToString" comparation error #20332
Comments
Only a small part of the |
Correct, we do not track Desktop/full .NET Framework bugs on GitHub. |
@JonHanna :For 4.6 is only my sample and later I found that this bug DID exist in almost all kinds of known versions of frameworks since 2.0. And I've checked the issue, the following versions have such a problem (My PC is x86, x64 isn't checked yet). 2.0, 3.5, 4.6 |
It's not in corefx though. |
So you mean that I can also directly report this issue on Microsoft's Connect platform of bugs, no matters how many versions it has? |
It's likely a good idea to include as much information about it as you can. Really, I don't know much about Connect except from having reported a couple of issues there in the past myself. With one of those the method in question was made later part of corefx and I was able to do something more proactive about it. Since |
OK, I'll have a try. |
|
@safern can suggest whether fixing this would be unacceptably breaking. |
I don't think this would be breaking as we don't use the ImageFormat.ToString() to compare anything, we do it directly we .Equals method that compares the Guid of the ImageFormat directly. I think the fix would be instead of doing this == s_jpeg to either do |
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
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.
The text was updated successfully, but these errors were encountered: