【问题标题】:Determine bit depth of bmp file on os x确定 os x 上 bmp 文件的位深度
【发布时间】:2023-04-08 09:15:01
【问题描述】:

如何在 Mac OS X 上确定 bmp 文件的位深度?特别是,我想检查 bmp 文件是否是真正的 24 位文件,或者它是否被保存为灰度(即 8 位)图像。我有一个黑白图像,我认为我已经强制为 24 位(使用 convert -type TrueColor),但 Imagemagick 给出了相互矛盾的结果:

> identify -verbose hiBW24.bmp
...
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray

> identify -debug coder hiBW24.bmp   
...
Bits per pixel: 24

许多其他命令行实用程序似乎没有帮助:

> file hi.bmp 
hi.bmp: data

> exiv2 hiBW24.bmp 
File name       : hiBW24.bmp
File size       : 286338 Bytes
MIME type       : image/x-ms-bmp
Image size      : 200 x 477
hiBW24.bmp: No Exif data found in the file

> mediainfo -f hi.bmp
...[nothing useful]

【问题讨论】:

  • 挑剔:“灰度(即 8 位)”是错误的方法。 BMP 支持 8 位颜色索引格式,但这本身并不表示它是灰度的。这与支持两者的 PNG 不同。

标签: macos image-processing command-line imagemagick bmp


【解决方案1】:

如果您想要一个推荐行实用程序,请尝试sips(不要忘记阅读带有man sips 的手册页)。示例:

*terminal input*
sips -g all /Users/hg/Pictures/2012/03/14/QRCodeA.bmp

*output is:*
/Users/hg/Pictures/2012/03/14/QRCodeA.bmp
pixelWidth: 150
pixelHeight: 143
typeIdentifier: com.microsoft.bmp
format: bmp
formatOptions: default
dpiWidth: 96.000
dpiHeight: 96.000
samplesPerPixel: 3
bitsPerSample: 8
hasAlpha: no
space: RGB

我认为结果包含您所追求的值。

另一种方法是使用预览器preview.app 打开图像并打开信息面板。

Phil Harvey http://www.sno.phy.queensu.ca/~phil/exiftool/ 的 exiftool 是信息量最大的程序之一(但不容易使用),它在 MacOSX 上也能很好地处理许多文件格式,但对您的目的来说可能有点过头了。

【讨论】:

  • 谢谢!不知道啜饮。不幸的是,它似乎将 8bpp bmp 文件识别为 samplesPerPixel=3,bitsPerSample=8,preview.app 信息面板也是如此。但是 exiftool 做得对,Bit Depth: 8 for an 8bpp bmp and Bit Depth: 24 for a 24bpp version.所以谢谢!
【解决方案2】:

我这样做是为了调查:

# create a black-to-white gradient and save as a BMP, then `identify` it to a file `unlim`
convert -size 256x256 gradient:black-white a.bmp
identify -verbose a.bmp > unlim

# create another black-to-white gradient but force 256 colours, then `identify` to a second file `256`
convert -size 256x256 gradient:black-white -colors 256 a.bmp
identify -verbose a.bmp > 256

# Now look at difference
opendiff unlim 256

不同之处在于-colors 256图像在标题中有一个调色板并且有一个Class:PseudoClass,而另一个有Class:Direct

【讨论】:

  • 很有趣,尽管我对像这样间接推断 BPP 持谨慎态度。很好地使用 opendiff(我不知道)。最简单的解决方案似乎是 exiftool,正如 Heinrich Giesen 在另一个答案中所推荐的那样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-14
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 2012-01-04
相关资源
最近更新 更多