GDI +: black and white PNG loads as PixelFormat32bppARGB

I am trying to load a PNG file in grayscale using GDI + on Windows 7 / 64bits Pro. However, if I use the value returned from Image :: GetPixelFormat () , it tells me that pixelFormat has a value PixelFormat32bppARGB

.

If I convert this PNG to JPG and / or TIFF, it now tells me that pixelFormat is now PixelFormat8bppIndexed

.

Looking at the definition of the thoses values here says little. However, looking at here shows what PixelFormat32bppARGB

the result actually is (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical)

.

My questions:

  • What does the following mean PixelFormatCanonical: Is in canonical format

    :?
  • I understand that GDI + can represent a single grayscale image as 32bpp ARGB, non-premultiplied alpha, but how can I check if the underlying representation is actually grayscale? This will be helpful as I only want to copy one component from the ARGB buffer.

Below is the information from a PNG file using a command pnginfo

from the UNIX shell:

$ pnginfo input.png
input.png...
  Image Width: 2492 Image Length: 3508
  Bitdepth (Bits/Sample): 8
  Channels (Samples/Pixel): 1
  Pixel depth (Pixel Depth): 8
  Colour Type (Photometric Interpretation): GRAYSCALE 
  Image filter: Single row per byte filter 
  Interlacing: No interlacing 
  Compression Scheme: Deflate method 8, 32k window
  Resolution: 11811, 11811 (pixels per meter)
  FillOrder: msb-to-lsb
  Byte Order: Network (Big Endian)
  Number of text strings: 0 of 0

      

It's even a problem with the wine

GDI + implementation . Current wine 1.6.2 also believe that my input PNG really: PixelFormat8bppIndexed

.

+3


source to share


2 answers


After doing all the possible functions from the GDI + Image class, I found a solution. Need to extract flags from image and check for ImageFlagsColorSpaceGRAY

For grayscale PNG:

  • PixelFormat: PixelFormat32bppARGB

  • ImageFlagsColorSpaceGRAY

    installed ( notImageFlagsColorSpaceRGB

    installed )

For RGB PNG:



  • PixelFormat: PixelFormat24bppRGB

  • ImageFlagsColorSpaceRGB

    installed ( notImageFlagsColorSpaceGRAY

    installed )

For RGBA PNG:

  • PixelFormat: PixelFormat32bppARGB

  • ImageFlagsColorSpaceRGB

    installed ( notImageFlagsColorSpaceGRAY

    installed )
+2


source


1: The page you linked for flags is a page from Windows CE, have you confirmed that the flags in your Windows SDK are actually the same?

2: Image :: GetPixelFormat tells you the pixel format of the Image object, which shouldn't be the same as the PNG file.



There is a note at the bottom of the page describing pixel formats :

PixelFormat48bppRGB, PixelFormat64bppARGB, and PixelFormat64bppPARGB use 16 bits per color component (channel). Windows GDI + version 1.0 can read 16-bit images per channel, but such images are converted to 8-bits per channel for processing, display, and storage.

0


source







All Articles