Skip to content
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

System.Drawing.Image.FromStream returns a Bitmap with incorrect PixelFormat #22

Open
AndrewKaplanovsky opened this issue Aug 5, 2016 · 2 comments
Assignees
Labels

Comments

@AndrewKaplanovsky
Copy link

Hi Anders, so sorry for disturbing you again.

I have an image stored on a disk, .bmp file with PixelFormat = Format1bppIndexed.
I try to load this file from Stream in my UWP application:

using (Stream stream = ResourcesUtils.GetResourceByID(ResourcesUtils.RES_BOARDMASK_20x20))
{
Bitmap bmpMask = (Bitmap)System.Drawing.Image.FromStream(stream);
...
}

When I check the PixelFormat of bmpMask, it's Format32bppArgb.

Is this a correct behavior or a bug in Shim.Drawing?

@anders9ustafsson
Copy link
Contributor

@AndrewKaplanovsky Yes, this is intended behavior. I have implemented the cast operator this way to ensure that the bitmap can be sufficiently processed further ahead.

Admittedly, the pixel format change may in some cases be overly intrusive, but I applied the "better-safe-than-sorry" approach here.

I should of course be more informative about this, perhaps in the wiki or something. I'll make sure to add some comments about it.

Is the pixel format change causing you problems, or were you primarily concerned of the undocumented behavior?

@AndrewKaplanovsky
Copy link
Author

@anders9ustafsson, the problem is I store a mask, which I'm applying to an image, in a file. I know the format of the stored bmp is 1bpp, indexed color. But when I load it, instead of getting an indexed 1bpp image, I get the 32bpp image again :) So I need to convert it back to 1bpp, which is a very time consuming operation in my case. But anyway, thanks for letting me know, I've found another solution in my case, I just generate a matrix literal based on a mask image once and then use it in my app instead of a mask stored in a file.

Thank you very much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants