我正在尝试在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
? 以下是在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:
PixelFormat32bppARGB
ImageFlagsColorSpaceGRAY
(设置了ImageFlagsColorSpaceRGB
而不是设置了)对于RGB PNG:
PixelFormat24bppRGB
ImageFlagsColorSpaceRGB
(设置了ImageFlagsColorSpaceGRAY
而不是设置了)对于RGBA PNG:
PixelFormat32bppARGB
ImageFlagsColorSpaceRGB
(设置了ImageFlagsColorSpaceGRAY
而不是设置了)