from PIL import Image
# Create 64x64 RGB image in blue
RGB = Image.new('RGB', (64,64), 'blue')
# Convert mode to RGBA
RGBA = RGB.convert('RGBA')
print(RGBA)
字符串
输出:
图像现在是RGBA:
<PIL.Image.Image image mode=RGBA size=64x64>
from PIL import Image
# Create 64x64 RGB image in blue
im = Image.new('RGB', (64,64), 'blue')
# Push in an alpha channel, forcing mode change from RGB to RGBA
im.putalpha(32)
print(im)
3条答案
按热度按时间cuxqih211#
字符串
Python Imaging Library(PIL)中的convert方法Pillow用于更改图像模式。对于PNG图像,有时可能未将模式设置为“RGBA”(红色、绿色、蓝色、Alpha),其中包括用于透明度的Alpha通道。
b1zrtrql2#
字符串
putalpha是从0到255,它定义了背景的透明度,但首先你必须将你的图像作为PNG引入,所以你必须对编译器说我的图像是RGBA,它有一个Alpha(红色,绿色,蓝色,Alpha(透明度))
vql8enpb3#
没有理由你不能做你想做的事情。有多种方法可以从RGB图像到RGBA图像。我将展示两种方法,用水平线分隔。
字符串
输出:
图像现在是RGBA:
的数据
输出:
图像已从RGB强制转换为RGBA:
型