none
Saving bitmap in PixelFormat1bppIndexed generates strange errors RRS feed

  • Question

  • I have a bitmap with a raster. The bitmap is converted into a monochrome format. When saving the bitmap to disk I get some strange behaviour. It seems to be a success, but the raster is changed. It's changed uniformly but still changed. I get the error when saving as bitmap, but not when saving as png. I would really like to get this to work without making my own save method (again).

    Here is the code:

    var original = new Bitmap(filename); // Although I don't get the bitmap from a file in the real code
    var rectangle = new Rectangle(0, 0, original.Width, original.Height);
    var bmp1bpp = original.Clone(rectangle, PixelFormat.Format1bppIndexed);
    
    bmp1bpp.Save(@"C:\Temp\Mono.bmp", ImageFormat.Bmp); 
    bmp1bpp.Save(@"C:\Temp\Mono.png", ImageFormat.Png);
    In the code above, "Mono.bmp" will have strange errors. "Mono.png" will be correct.
    I've tried other formats as well (not all). So far it's just BMP that I have problems with and that's the one that I need!

    Thursday, December 20, 2018 5:25 PM

Answers

  • Hi!
    It was Paint that didn't work. I usually like Paint because it is WYSIWYG. It shows the pixels as they are. No anti-aliasing etc. But now it didn't work with some of the BMP-images. It worked with the same image in PNG.

    I used large 4800x4400 BMP with 1 bit per pixel in both PNG and BMP.

    I saw that Paint 3D works fine though, so that's my choise in the future.

    I took some screendumps but I'm not allowed to upload them here unfortunately.

    But the problem was that "Paint" did something strange with some of the images. "Paint 3D" works fine though!

    It was not a problem with .NET Framework fortunately!

    • Marked as answer by Jleol Friday, December 21, 2018 3:04 PM
    Friday, December 21, 2018 2:14 PM

All replies

  • I tried to upload two images. One with the error and one without. I suddenly saw that it's Paint that can't handle this correct!

    Strange!

    It handles 1 bit png files correct, but not 1 bit bmp files. I haven't seen this before.

    Thursday, December 20, 2018 8:17 PM
  • Hi Jleol,

    Thank you for posting here.

    I test the code you provided, there is no error. Could you provide the image which could reproduce the error for me to test?

    The image below is the result which I test.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, December 21, 2018 8:49 AM
    Moderator
  • Hi!
    It was Paint that didn't work. I usually like Paint because it is WYSIWYG. It shows the pixels as they are. No anti-aliasing etc. But now it didn't work with some of the BMP-images. It worked with the same image in PNG.

    I used large 4800x4400 BMP with 1 bit per pixel in both PNG and BMP.

    I saw that Paint 3D works fine though, so that's my choise in the future.

    I took some screendumps but I'm not allowed to upload them here unfortunately.

    But the problem was that "Paint" did something strange with some of the images. "Paint 3D" works fine though!

    It was not a problem with .NET Framework fortunately!

    • Marked as answer by Jleol Friday, December 21, 2018 3:04 PM
    Friday, December 21, 2018 2:14 PM