简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM