Kivy how to rotate a picture

nukedbit picture nukedbit · Jul 16, 2013 · Viewed 7.4k times · Source

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

Answer

tito picture tito · Jul 17, 2013

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()

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.