问题
i tried to convert 8bit PNGs to 8bit(256indexed palette) Bitmap image, but Pillow is keep vomiting crappy outcome.
this is what i tried.
image = Image.open(file)
image = image.convert('P')
pp = image.getpalette()
pp[0] = 255
pp[1] = 0
pp[2] = 255
image.putpalette(pp)
or
image = Image.open(file)
image = image.convert('P')
image.save(blabla.bmp)
and this is the outcome what i expected to see. this is an actual bitmap(done by Photoshop.) Photoshop and this is what Pillow did: Pillow what kind of joke is this ?! and it even got cropped out what should i do to convert it correctly?
Original Image:
回答1:
You can do it like this:
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)
来源:https://stackoverflow.com/questions/56800095/pillow-convert-png-to-8bit-bitmap