将图像调整为可变/固定尺寸? [英] Resizing an image to variable/fixed dimensions?
问题描述
假设您有一个3行1列的GridLayout.第一行和最后一行将是标签",而中间行将包含一个图像.
Let's say you have a GridLayout with 3 rows and 1 column. The first and last rows will be Labels, and the middle row will contain an image.
调整图像大小以使其具有固定高度(与标签高度相同或不相同)并且宽度与布局宽度相同的最佳方法是什么?是否可以在kivy内执行此操作,还是有必要引入其他模块(例如PIL)并使用图像缓冲区?仅创建一个以图像为背景的非绑定按钮是否合理(因此,让kivy负责调整大小),还是这种解决方案有问题?谢谢.
What is the best way to resize the image such that it has a fixed height (may or may not be the same height as the Labels), and its width is the same as the width of the layout? Is it possible to do this within kivy, or is it necessary to bring in some other module, such as PIL, and use an image buffer? Would it be reasonable just to create a non-binded button with the image as a background (thus, letting kivy take care of the resizing), or is there a problem with this solution? Thanks.
推荐答案
调整图像大小以使其具有固定高度(与标签高度相同或不相同)并且宽度与布局宽度相同的最佳方法是什么?
What is the best way to resize the image such that it has a fixed height (may or may not be the same height as the Labels), and its width is the same as the width of the layout?
我不确定您在这里问的是什么.您是否在谈论图像"小部件?您可以使用
I'm not sure exactly what you're asking here. Are you talking about the Image widget? You could do this with
Image:
source: 'whatever'
size_hint_y: None # Tells the layout to ignore the size_hint in y dir
height: dp(40) # The fixed height you want