我正在尝试在Windows 7/64bits Pro上使用GDI +加载灰度PNG文件。但是,如果我使用Image::GetPixelFormat()返回的值,它会告诉我pixelFormat是PixelFormat32bppARGB

如果我将此PNG转换为JPG和/或TIFF,它现在告诉我pixelFormat现在是PixelFormat8bppIndexed

查看这些值here的定义并不能说明太多。然而,将它们视为here会发现PixelFormat32bppARGB实际上是(10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical)的结果。

我的问题是:

  • 以下是什么意思:PixelFormatCanonical: Is in canonical format
  • 我知道GDI +可以自由地将单分量灰度图像表示为32bpp ARGB(非预乘alpha),但是然后如何检查基础表示实际上是灰度的呢?因为我只想从ARGB缓冲区复制单个分量,所以这将证明是有用的。

  • 以下是在UNIX shell中使用pnginfo命令从PNG文件获得的一些信息:
    $ 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
    

    这甚至与GDI +的wine实现有关。当前wine 1.6.2也认为我的输入PNG实际上是:PixelFormat8bppIndexed

    最佳答案

    在尝试了GDI + Image类的所有可能功能之后,我认为找到了解决方案。需要从镜像中检索flags并针对ImageFlagsColorSpaceGRAY进行测试

    对于灰度PNG:

  • PixelFormat是:PixelFormat32bppARGB
  • 设置了
  • ImageFlagsColorSpaceGRAY(设置了ImageFlagsColorSpaceRGB而不是设置了)

  • 对于RGB PNG:
  • PixelFormat是:PixelFormat24bppRGB
  • 设置了
  • ImageFlagsColorSpaceRGB(设置了ImageFlagsColorSpaceGRAY而不是设置了)

  • 对于RGBA PNG:
  • PixelFormat是:PixelFormat32bppARGB
  • 设置了
  • ImageFlagsColorSpaceRGB(设置了ImageFlagsColorSpaceGRAY而不是设置了)
  • 10-04 16:00
    查看更多