Python PIL How do I convert 1 bit deep images to RGBA?

守給你的承諾、 提交于 2021-01-27 12:01:56

问题


Exactly like the title. I take a single-band image of mode "1" and open it using

image = Image.open("picture.tif")

I then try to convert it to RGBA with

image.convert("RGBA")

And then whenever I check the mode of it using

print(image.mode)

I get that it's still "1". I've even tried this using "L" (which is another single-band image mode) and still no luck. No matter what I do, it won't convert. Searching the web only seems to reveal converting from "RGBA" to "1" but I haven't been able to find anything about the other way around. Is there ANY way (even outside Python) to convert 1 bit deep images to RGBA?

Help?


回答1:


image.convert doesn't change the mode of the image, it returns a new image with the new mode.

image = image.convert("RGBA")

From the documentation:

Unless otherwise stated, all methods return a new instance of the Image class, holding the resulting image.



来源:https://stackoverflow.com/questions/12270163/python-pil-how-do-i-convert-1-bit-deep-images-to-rgba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!