本文介绍了枕头将png转换为8bit位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将8位PNG转换为8位(256索引调色板)位图图像,但是枕头一直在呕吐糟糕的结局.
i tried to convert 8bit PNGs to 8bit(256indexed palette) Bitmap image,but Pillow is keep vomiting crappy outcome.
这就是我尝试过的.
image = Image.open(file)
image = image.convert('P')
pp = image.getpalette()
pp[0] = 255
pp[1] = 0
pp[2] = 255
image.putpalette(pp)
或
image = Image.open(file)
image = image.convert('P')
image.save(blabla.bmp)
这就是我期望看到的结果.这是一个实际的位图(由Photoshop完成). Photoshop 这是枕头做的:枕头这是什么玩笑?甚至被裁剪掉了我应该怎么做才能正确转换它?
and this is the outcome what i expected to see.this is an actual bitmap(done by Photoshop.)Photoshopand this is what Pillow did:Pillowwhat kind of joke is this ?!and it even got cropped outwhat should i do to convert it correctly?
原始图片:
推荐答案
您可以这样做:
from PIL import Image
# Open image
image = Image.open('feather.png')
# Quantize to 256 colours using fast octree method
result = image.quantize(colors=256, method=2)
这篇关于枕头将png转换为8bit位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!