c++ - GDI+:灰度 PNG 加载为 PixelFormat32bppARGB

标签 c++ windows gdi+

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

如果我将此 PNG 转换为 JPG 和/或 TIFF,它现在会告诉我像素格式现在是 PixelFormat8bppIndexed .

查看这些值的定义 here , 不多说。然而看着他们here , 表明 PixelFormat32bppARGB实际上是 (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical) 的结果.

我的问题是:

  1. 以下是什么意思:PixelFormatCanonical: Is in canonical format
  2. 我知道 GDI+ 可以自由地将单分量灰度图像表示为 32bpp ARGB、非预乘 alpha,但是我如何检查底层表示实际上是灰度图像?这将被证明是有用的,因为我只想从 ARGB 缓冲区复制一个组件。

以下是使用 pnginfo 从 PNG 文件中获取的一些信息来自 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

这甚至是 wine 的问题GDI+的实现。当前 wine 1.6.2还认为我输入的 PNG 真的是:PixelFormat8bppIndexed .

最佳答案

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

对于灰度 PNG:

  • 像素格式为:PixelFormat32bppARGB
  • ImageFlagsColorSpaceGRAY 已设置(ImageFlagsColorSpaceRGB 设置)

对于 RGB PNG:

  • 像素格式为:PixelFormat24bppRGB
  • ImageFlagsColorSpaceRGB 已设置(ImageFlagsColorSpaceGRAY 设置)

对于 RGBA PNG:

  • 像素格式为:PixelFormat32bppARGB
  • ImageFlagsColorSpaceRGB 已设置(ImageFlagsColorSpaceGRAY 设置)

关于c++ - GDI+:灰度 PNG 加载为 PixelFormat32bppARGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30391832/

相关文章:

c++ - VS2017 #错误 : : Macro definition of snprintf conflicts with Standard Library function declaration

c++ - 错误 C4996 : 'ctime' : This function or variable may be unsafe

c++ - 如何让不同的进程使用Windows 7不同的网络接口(interface)?

c++ - 如何将 GDI+ 状态转换为字符串?

.net - 优化 GDI+ 函数的性能

c++ - 要在 scanf() 的扫描集中包含一个连字符作为元素,它应该是列表中的第一个字符还是最后一个字符?

c++ - 在c++中,是否可以为模板类指定部分参数

windows - 远程 : fatal: unresolved deltas left after unpacking

windows - 32 位和 64 位 DLL 如何链接到同一个 C :\system32\kernel32. DLL?

c# - 在 3D 空间中旋转图像的一部分