Kivy如何旋转图片 [英] Kivy how to rotate a picture

查看:109
本文介绍了Kivy如何旋转图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试旋转一些我必须在屏幕上显示的图片,这些图片位于堆栈布局内,我需要将它们显示为纵向"而不是横向",我正在使用图像"小部件 谢谢

i'm trying to rotate some pictures i have to show on the screen, these picture are inside a stacklayout, and i need to show them as Portrait instead of landscape,i'm using the Image Widget Thanks

推荐答案

toto_tico的前2个答案是一种方法,但是我宁愿为其创建一个新的小部件并使用它:

The previous 2 answer of toto_tico is a way to do, but i would rather create a new widget for it, and use it:

Builder.load_string('''
<RotatedImage>:
    canvas.before:
        PushMatrix
        Rotate:
            angle: root.angle
            axis: 0, 0, 1
            origin: root.center
    canvas.after:
        PopMatrix
''')

class RotatedImage(Image):
    angle = NumericProperty()

然后,将此小部件与其他图像"小部件一起使用,您只需具有一个"angle"属性即可使用.

Then, use this widget as other Image widget, you just have a "angle" property you can play with.

注意:除了散点图示例外,不对图像进行碰撞检测.仅仅为了旋转某些物体,散射可能会很昂贵,但至少碰撞会起作用.

Note: the collision detection is not handled on the image, except in the scatter example. Scatter can be expensive just for rotate something, but at least the collision works.

这篇关于Kivy如何旋转图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆