C# Why Bitmap.Save ignores PixelFormat of Bitmap?

后端 未结 4 563
北恋
北恋 2021-01-13 19:24

I need to process and save images in their original bpp (1 - for BnW, 8 - for gray, 24 - color). After processing I always have 24bpp (due to processing with Aforge.Net). I

4条回答
  •  温柔的废话
    2021-01-13 20:05

    Here is the code that will convert a Bitmap to 1bpp/8bpp bitmap. 1bpp/8bpp in C#.

    In your changePixelFormat method you can check what fixel format it needs to be converted to, then if it's 1bpp or 8 bpp then use code from link and for all other formats use your code.

    Graphics.FromImage documentation has remarks:

    If the image has an indexed pixel format, this method throws an exception with the message, "A Graphics object cannot be created from an image that has an indexed pixel format." The indexed pixel formats are shown in the following list.

    Format1bppIndexed

    Format4bppIndexed

    Format8bppIndexed

    NEW PART:

    This is what i found after short googling:

    8bpp greyscale images and 8bpp jpg is not supported with gdiplus version 1.0. There is a new version of gdiplus in Windows 7 that supports greyscale images and more enhanced codec support.

    8bpp indexed jpeg images are supported with Microsoft's WIC API.

    You can try it yourself by downloading the WIC explorer from Microsoft's download site.

    GDI+ 8 bit load/save bug

    Standard JPEG only supports 24-bit image.

提交回复
热议问题