Python PIL如何将1位深的图像转换为RGBA? [英] Python PIL How do I convert 1 bit deep images to RGBA?

查看:79
本文介绍了Python PIL如何将1位深的图像转换为RGBA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与标题完全一样.我拍摄模式为"1"的单波段图像,并使用

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

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

然后我尝试将其转换为RGBA

I then try to convert it to RGBA with

image.convert("RGBA")

然后每当我使用

print(image.mode)

我知道它仍然是"1".我什至尝试过使用"L"(这是另一种单波段图像模式),但还是没有运气.不管我做什么,都不会转换.搜索网络似乎只显示了从"RGBA"到"1"的转换,但是我无法找到任何其他方式.是否有任何方法(甚至在Python之外)也可以将1位深的图像转换为RGBA?

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?

帮助?

推荐答案

image.convert 不会更改图像的模式,它将返回具有新模式的新图像.

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

image = image.convert("RGBA")

来自文档:

除非另有说明,否则所有方法都将返回Image类的新实例,并保存生成的图像.

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

这篇关于Python PIL如何将1位深的图像转换为RGBA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆