开发者

PIL save as 24 bit true color bitmap

开发者 https://www.devze.com 2023-01-11 22:58 出处:网络
I have a png file generated by Gnuplot that I need to put into an excel document using XLWT. XLWT can\'t import PNG\'s into the document, only BMP\'s, so I needed to convert the PNG first. I used PIL

I have a png file generated by Gnuplot that I need to put into an excel document using XLWT.

XLWT can't import PNG's into the document, only BMP's, so I needed to convert the PNG first. I used PIL for this.

Here's the relevant code:

im = Image.open('%s' % os.path.join(os.getcwd(), s + '.png'))
im.save('%s.bmp' % s)

However XLWT gives me this error:

Exception: bitmap isn't a 24bit true color bitmap.

Here's what the XLWT code looks like:

self.chart.insert_bitmap(path, 2, 2) 

I know both images work fine, they're both openable by windows. I've also tried adding a 2 s开发者_如何学Cecond pause after creating the BMP (to make up for write time), but it still fails.

How do I go about making a 24 bit true color bitmap using PIL?


Nevermind! Just figured it out myself.

Change

im = Image.open('%s' % os.path.join(os.getcwd(), s + '.png'))

To

im = Image.open('%s' % os.path.join(os.getcwd(), s + '.png')).convert("RGB")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号