我使用PIL和Numpy在tkintergui中显示图像之前向图像添加alpha通道。我首先读取图像,将其转换为“RGBA”,将其转换为数组,添加alpha通道,转换回图像,在Tkinter GUI中显示。在
这是我的代码:
import numpy as NP
import PIL.Image, PIL.ImageTk
from Tkinter import *
root=Tk()
image = PIL.Image.open('A.png')
image = image.convert('RGBA')
Arr=NP.array(image)
#apply alpha of 100
Arr[..., 3] = 100
TKimg=PIL.ImageTk.PhotoImage(PIL.Image.fromarray(Arr))
Label(root, image=TKimg,background='white').pack()
root.mainloop()
这是我在windows和linux上运行代码时得到的the result。在
原始图像的背景是白色的。在windows中添加alpha后,它仍然是白色背景“我想要的”。然而,背景中的白色被摧毁了。在
那么如何在linux中应用alpha并保持白色背景呢 有没有什么方法可以用python实现呢
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐