Loading 8bpp grayscale images in C# Bitmap

37 Views Asked by At

BMP and PNG files are loaded with different pixel formats, even if external tools show 8bpp grayscale for them

Every time when I'm loading 8bits grayscale bmp image to C# Bitmap, it's loaded as 8bit indexed image, somehow c# change pixelformat from 8bits grayscale to 8bits indexed and create gray color pallet.

For PNG images pixel format is changed to 32RGB.

Due to the further processing, they must remain as 8bits greyscale bitmap

        public void LoadFromFile(string filename)
        {
            var bmp = new Bitmap(filename, true);
            Console.WriteLine($"bmp pf = {bmp.PixelFormat.ToString()}");
        }

Maybe there is some way to load that files with correct pixel format? Bitmap constructor do not allow me specify pixelformat

0

There are 0 best solutions below