简体   繁体   English

Python PIL如何将1位深度图像转换为RGBA?

[英]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 我拍摄模式为“1”的单波段图像并使用它打开

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

I then try to convert it to RGBA with 然后我尝试将其转换为RGBA

image.convert("RGBA")

And then whenever I check the mode of it using 然后每当我检查它的模式使用

print(image.mode)

I get that it's still "1". 我知道它仍然是“1”。 I've even tried this using "L" (which is another single-band image mode) and still no luck. 我甚至尝试使用“L”(这是另一种单波段图像模式),但仍然没有运气。 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. 仅在网上搜索似乎显示从“RGBA”转换为“1”,但我无法找到任何相关的方法。 Is there ANY way (even outside Python) to convert 1 bit deep images to RGBA? 是否有任何方法(甚至在Python之外)将1位深度图像转换为RGBA?

Help? 救命?

image.convert doesn't change the mode of the image, it returns a new image with the new mode. image.convert不会改变图像的模式,它会以新模式返回一个新图像。

image = image.convert("RGBA")

From the documentation : 文档

Unless otherwise stated, all methods return a new instance of the Image class, holding the resulting image. 除非另有说明,否则所有方法都会返回Image类的新实例,并保留生成的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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