Kivy图像周围的白色条带

时间:2016-02-09 15:28:52

标签: python image kivy

我从外部网站提取图片并按固定尺寸框顺序显示每个图片。设置拉伸图像以填充框的约束,但保持纵横比。因为图像不总是与盒子的纵横比相匹配,所以我在图像周围得到白色条带。我无法弄清楚如何摆脱白色乐队。我尝试使用canvas.before尝试将盒子涂成黑色,但它没有用。

图像(和相关信息)是从Python推送的:

class TheBox(FloatLayout):
    def update(self, *args):
        ..
        ..
        if (total_count % 2) == 0: 
            if which_petL < quantity:
                which_petL += 1
            else:
                which_petL = 0

            self.ids.PetL_photo.source = str(Lphoto)

kv:

#:kivy 1.9.1

<TheBox>:
    FloatLayout:
        FloatLayout:
            size: 810, 1080
            pos_hint: {'center_x': .21}         
            AsyncImage:
                id: PetL_photo
                size_hint: None, None
                size: 790, 770
                pos_hint: {'center_x': .5, 'center_y': .64} 
                allow_stretch: True
                keep_ratio: True
                source:
            ..
            ..

结果:

http://cselman.com/20160209_093304.mp4

任何帮助?

canvas.before尝试:

#:kivy 1.9.1

<TheBox>:
    FloatLayout:
        FloatLayout:
            size: 810, 1080
            pos_hint: {'center_x': .21}         
            AsyncImage:
                canvas.before:
                    Color:
                        rgb: (0, 0, 0)
                id: PetL_photo
                size_hint: None, None
                size: 790, 770
                pos_hint: {'center_x': .5, 'center_y': .64} 
                allow_stretch: True
                keep_ratio: True
                source:

和...

#:kivy 1.9.1

<TheBox>:
    canvas.before:
        Color:
            rgb: (0, 0, 0)
    FloatLayout:
        FloatLayout:
            size: 810, 1080
            pos_hint: {'center_x': .21}         
            AsyncImage:
                id: PetL_photo
                size_hint: None, None
                size: 790, 770
                pos_hint: {'center_x': .5, 'center_y': .64} 
                allow_stretch: True
                keep_ratio: True
                source:

和...

#:kivy 1.9.1

<TheBox>:
    FloatLayout:
        FloatLayout:
            size: 810, 1080
            pos_hint: {'center_x': .21}
            canvas.before:
                Color:
                    rgb: (0, 0, 0)      
            AsyncImage:
                id: PetL_photo
                size_hint: None, None
                size: 790, 770
                pos_hint: {'center_x': .5, 'center_y': .64} 
                allow_stretch: True
                keep_ratio: True
                source:

1 个答案:

答案 0 :(得分:1)

添加矩形是我所缺少的。

#:kivy 1.9.1

<TheBox>:
    FloatLayout:
        FloatLayout:
            size: 810, 1080
            pos_hint: {'center_x': .21}
            AsyncImage:
                canvas.before:
                    Color:
                        rgb: (0, 0, 0)
                    Rectangle:
                        pos: self.pos
                        size: self.size
                id: PetL_photo
                size_hint: None, None
                size: 790, 770
                pos_hint: {'center_x': .5, 'center_y': .64} 
                allow_stretch: True
                keep_ratio: True
                source:
相关问题