如何改变图像kivy的不透明度
how to change opacity of image kivy
如何将图像的透明度更改为 50%?
class MyBackground(Widget):
def __init__(self, **kwargs):
x = randint(1,10)
print (x)
y = 'water.png'
if x==1:
y = 'a.png'
if x==2:
y = 'b.png'
if x==3:
y = 'c.png'
if x==4:
y = 'd.png'
if x==5:
y = 'e.png'
if x==6:
y = 'f.png'
if x==7:
y = 'g.png'
if x==8:
y = 'h.png'
if x==9:
y = 'i.png'
if x==10:
y = 'j.png'
super(MyBackground, self).__init__(**kwargs)
with self.canvas:
self.bg = Rectangle(source=y, pos=self.pos, size=self.size)
self.bind(pos=self.update_bg)
self.bind(size=self.update_bg)
如何在不更改 rgb 值的情况下执行此操作?如果我尝试它最终会变成白色。
你尝试了吗
with self.canvas:
self.opacity = 0.5
self.bg = Rectangle(source=y, pos=self.pos, size=self.size)
self.bind(pos=self.update_bg)
self.bind(size=self.update_bg)
参考:http://kivy.org/docs/api-kivy.graphics.instructions.html#kivy.graphics.instructions.Canvas.opacity
在你的kivy文件中
进行这些修改
Color:
rgb: (1, 1, 1,a)
在 docs
中检查此 link
Image color, in the format (r, g, b, a).
其中 'a'
是 alpha。
将 alpha 部分设置为您想要的不透明度级别将为您提供图像不透明度。
如何将图像的透明度更改为 50%?
class MyBackground(Widget):
def __init__(self, **kwargs):
x = randint(1,10)
print (x)
y = 'water.png'
if x==1:
y = 'a.png'
if x==2:
y = 'b.png'
if x==3:
y = 'c.png'
if x==4:
y = 'd.png'
if x==5:
y = 'e.png'
if x==6:
y = 'f.png'
if x==7:
y = 'g.png'
if x==8:
y = 'h.png'
if x==9:
y = 'i.png'
if x==10:
y = 'j.png'
super(MyBackground, self).__init__(**kwargs)
with self.canvas:
self.bg = Rectangle(source=y, pos=self.pos, size=self.size)
self.bind(pos=self.update_bg)
self.bind(size=self.update_bg)
如何在不更改 rgb 值的情况下执行此操作?如果我尝试它最终会变成白色。
你尝试了吗
with self.canvas:
self.opacity = 0.5
self.bg = Rectangle(source=y, pos=self.pos, size=self.size)
self.bind(pos=self.update_bg)
self.bind(size=self.update_bg)
参考:http://kivy.org/docs/api-kivy.graphics.instructions.html#kivy.graphics.instructions.Canvas.opacity
在你的kivy文件中 进行这些修改
Color:
rgb: (1, 1, 1,a)
在 docs
中检查此 linkImage color, in the format (r, g, b, a).
其中 'a'
是 alpha。
将 alpha 部分设置为您想要的不透明度级别将为您提供图像不透明度。