如何在Kivy中更改图像画布大小

时间:2019-02-17 16:41:22

标签: python image canvas kivy size

我用python Kivy在Raspberry Pi上制作了数字汽车仪表板,我需要实时显示RPM。 我有2张图片,scale7000.png和rpmBar.png

enter image description here enter image description here

我需要显示rpmBar.png的一部分,例如50% enter image description here

我正在创建图片:

# Create samples
set.seed(7)
my.df <- replicate(n=100, rnorm(4))

# Calculate mean of each column 
means <- apply(my.df, MARGIN = 2, mean)

# Calculate the function of each column (you could also use the function var)
variances <- apply(my.df, MARGIN = 2, FUN = function(x) (1/(length(x)-1) * (sum((x-mean(x))^2))))

如何设置新的画布尺寸?像这样的伪代码:

self.rpmBar = Image(source='rpmBar.png', size_hint=(None,None), height=154, width=800, pos=(0,240))
self.add_widget(self.rpmBar)

1 个答案:

答案 0 :(得分:0)

约翰·安德森(John Anderson)谢谢! StencilView是正确的方法

self.rpmBar = StencilView(size_hint=(None,None), size=(800,154),pos=(0,240))
self.rpmBarImage = Image(source='rpmBar.png', size=(800,154), pos=(0,240))
self.rpmBar.add_widget(self.rpmBarImage)
self.add_widget(self.rpmBar)

self.rpmBar.width = 500