我有一个 BMP 图像,我试图用 PIL 打开。然而,PIL 对这张图片感到窒息......
这是一个有效的图像。图像元数据如下:
sh:~/home/user$ identify -verbose badbmp.bmp
Image: badbmp.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: DirectClass
Geometry: 940x705+0+0
Units: PixelsPerCentimeter
Type: TrueColorMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit
Channel statistics:
Red:
min: 7 (0.027451)
max: 255 (1)
mean: 82.3111 (0.322788)
standard deviation: 42.3517 (0.166085)
kurtosis: 9.21784
skewness: 2.94025
Green:
min: 7 (0.027451)
max: 255 (1)
mean: 80.6959 (0.316454)
standard deviation: 43.208 (0.169443)
kurtosis: 8.72161
skewness: 2.84078
Blue:
min: 5 (0.0196078)
max: 255 (1)
mean: 76.912 (0.301616)
standard deviation: 45.1296 (0.176979)
kurtosis: 7.82117
skewness: 2.6619
Alpha:
min: 255 (1)
max: 255 (1)
mean: 255 (1)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Image statistics:
Overall:
min: 5 (0.0196078)
max: 255 (1)
mean: 123.73 (0.485215)
standard deviation: 84.6884 (0.332111)
kurtosis: -1.16829
skewness: 0.805031
Alpha: rgba(52,52,52,0) #34343400
Rendering intent: Undefined
Chromaticity:
red primary: (-nan,-nan)
green primary: (-nan,-nan)
blue primary: (-nan,-nan)
white point: (0,0)
Interlace: None
Background color: white
Border color: rgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Compose: Over
Page geometry: 940x705+0+0
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Properties:
date:create: 2013-05-29T13:41:17-07:00
date:modify: 2013-05-29T13:41:17-07:00
signature: 06a0f3720396f746fa94ee4918f3150c9bd4931ff21e9bed66d8202b4824e215
Artifacts:
verbose: true
Tainted: False
Filesize: 2.651MB
Number pixels: 663KB
Pixels per second: 66.27MB
User time: 0.010u
Elapsed time: 0:01.010
Version: ImageMagick 6.6.0-4 2012-08-17 Q16 http://www.imagemagick.org
我的代码如下所示:
imageBytes = None
with open(fileName, 'rb') as f:
imageBytes = f.read()
rawImage = Image.open(StringIO.StringIO(imageBytes))
当我尝试运行 htis 时,我得到以下信息:
File "/home/user/__init__.py", line 149, in convert_file_adv
rawImage = Image.open(StringIO.StringIO(imageBytes))
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1965, in open
return factory(fp, filename)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 91, in __init__
self._open()
File "/usr/lib/python2.7/dist-packages/PIL/BmpImagePlugin.py", line 170, in _open
self._bitmap(offset=offset)
File "/usr/lib/python2.7/dist-packages/PIL/BmpImagePlugin.py", line 102, in _bitmap
raise IOError("Unsupported BMP header type (%d)" % len(s))
IOError: Unsupported BMP header type (124)
有人可以帮助我了解如何解决此问题或解决此问题吗?