Reader Level:

Solution for "A Graphics Object cannot be Created from an Image that has an Indexed Pixel Format"

By Raguraman Ramamoorthy on Sep 10, 2007
In this article, you can learn how to avoid the issues/errors when you access/edit indexed pixel format images using few steps.

When you access/edit the following types of images we will get the error "a graphics object cannot be created from an image that has an indexed pixel format"

  • PixelFormatUndefined
  • PixelFormatDontCare
  • PixelFormat1bppIndexed
  • PixelFormat4bppIndexed
  • PixelFormat8bppIndexed
  • PixelFormat16bppGrayScale
  • PixelFormat16bppARGB1555

Solution for this problem:

The following code will fix the error.



    // create Image Object using rear image byte[]

    Image imag = Image.FromStream(new MemoryStream(imageR));

    // Derive BitMap object using Image instance, so that you can avoid the issue

    //"a graphics object cannot be created from an image that has an indexed pixel format"

    Bitmap img = new Bitmap(new Bitmap( imag ));


catch (Exception ex)




Article Extensions
Contents added by G B on Jun 18, 2011
If you override the image that has this problem, and explicitly save it as a 32 bit-depth colors (explicitly), the problem is gone too. Apparently this problem occurs if an image has a relatively low amount of used colors. In that case when storing the image as 'auto detect color-depth) it will persist in a lower amount which conflicts ... downside: size of images are somewhat bigger.
Raguraman Ramamoorthy
Raguraman Ramamoorthy

Working in .NET since BETA version. Almost worked in all areas in .NET platform. Basically creating a lot Banking/Check21 solutions/Check processing application using .NET and Mainframe COBOL. I love to do programming... Read more