如何获取jpg文件的深度? [英] How can I get the depth of a jpg file?
本文介绍了如何获取jpg文件的深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Python检索jpeg文件的位深度.
I want to retrieve the bit depth for a jpeg file using Python.
使用Python映像库:
Using the Python Imaging Library:
import Image
data = Image.open('file.jpg')
print data.depth
但是,对于明显的24位图像,这使我的深度为8.难道我做错了什么?有什么方法可以用纯Python代码做到这一点?
However, this gives me a depth of 8 for an obviously 24-bit image. Am I doing something wrong? Is there some way to do it with pure Python code?
谢谢.
它是data.bits而不是data.depth.
It's data.bits not data.depth.
推荐答案
我在模式被支持.您可以使用类似这样的内容:
I don't see the depth
attribute documented anywhere in the Python Imaging Library handbook. However, it looks like only a limited number of modes are supported. You could use something like this:
mode_to_bpp = {'1':1, 'L':8, 'P':8, 'RGB':24, 'RGBA':32, 'CMYK':32, 'YCbCr':24, 'I':32, 'F':32}
data = Image.open('file.jpg')
bpp = mode_to_bpp[data.mode]
这篇关于如何获取jpg文件的深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文