Search code examples
c#bitmappixelformat

The input image lost its PixelFormat during the loading process. c#


I want to load an image from my resources to a Bitmap, and save its Pixel Format. The input image is a .bmp file with 8 BitsPerPixel image depth. This is the code:

Bitmap inputImage = new Bitmap(Test.Resources.sourceImage);

When I debug the program and I check the properties of the sourceImage, its PixelFormat is PixelFormat.Format8bppIndexed. But after this variable assignment the PixelFormat of inputImage is Format32bppArgb.

Do you have any idea where is the problem?


Solution

  • var source = Test.Resources.sourceImage;
    Bitmap inputImage = source.Clone(new Rectangle(Point.Empty, source.Size), source.PixelFormat);