파이썬으로 bmp 파일의 헤더를 읽을 필요가 있습니다. 나는이 같은 시도했지만 분명히 비 이해할 바이트 만 무리를 반환파이썬에서 bmp 파일 헤더를 읽는 방법?
f = open(input_filename,"rb")
data = bytearray(f.read())
f.close()
print(data[:14])
내 아이디어를 여는 동안 이미지 정보를 기록하기 위해, 모듈, 또는 고속 무언가를 찾는 것이 었습니다. 나는 정확하게 원하는 것을 수행하는 matlab에서이 함수에 대해 알고있다 : imfinfo()
. 하지만 파이썬에서 대응 물을 찾을 수는 없습니다.
>>> import imghdr
>>> print(imghdr.what(input_filename))
bmp
이 이미지 유형을 추출합니다 :
FileModDate: '20-Oct-2017 09:42:24'
FileSize: 1311798
Format: 'bmp'
FormatVersion: 'Version 3 (Microsoft Windows 3.x)'
Width: 1280
Height: 1024
BitDepth: 8
ColorType: 'indexed'
FormatSignature: 'BM'
NumColormapEntries: 256
Colormap: [256x3 double]
RedMask: []
GreenMask: []
BlueMask: []
ImageDataOffset: 1078
BitmapHeaderSize: 40
NumPlanes: 1
CompressionType: 'none'
BitmapSize: 1310720
HorzResolution: 0
VertResolution: 0
NumColorsUsed: 256
NumImportantColors: 0
'PIL'의'Image.info'를 사용해 보셨습니까? http://effbot.org/imagingbook/image.htm#tag-Image.Image.info – jmetz
PIL이게'{ 'dpi': (0, 0), 'compression': 0}' – RobiNoob
입니다. 당신이'struct' 모듈을 봐야한다고 생각합니다. https://docs.python.org/3/library/struct.html#module-struct –