android拍照屏幕旋转90度,Kivy相机显示屏旋转-90度

它将在canvas.before编写的行上引发Parser Exception:

kivy.lang.parser.ParserException: Parser: File "", line 21:

I python  :  ...

I python  :       19:        height: '48dp'

I python  :       20:        on_press: root.capture()

I python  :  >>   21:    canvas.before:

I python  :       22:        PushMatrix

I python  :       23:        Rotate:

I python  :  ...

I python  :  Invalid class name

考虑到canvas.before和canvas.after只能在其他对象中调用,以下代码对我有用:

from kivy.app import App

from kivy.lang import Builder

from kivy.uix.boxlayout import BoxLayout

import time

Builder.load_string('''

:

orientation: 'vertical'

Camera:

id: camera

resolution: (640, 480)

play: False

canvas.before:

PushMatrix

Rotate:

angle: -90

origin: self.center

canvas.after:

PopMatrix

ToggleButton:

text: 'Play'

on_press: camera.play = not camera.play

size_hint_y: None

height: '48dp'

Button:

text: 'Capture'

size_hint_y: None

height: '48dp'

on_press: root.capture()

''')

class CameraClick(BoxLayout):

def capture(self):

'''

Function to capture the images and give them the names

according to their captured time and date.

'''

camera = self.ids['camera']

timestr = time.strftime("%Y%m%d_%H%M%S")

camera.export_to_png("IMG_{}.png".format(timestr))

print("Captured")

class TestCamera(App):

def build(self):

return CameraClick()

TestCamera().run()

资源:

https://kivy.org/doc/stable/examples/gen__canvas__rotation__py.html

https://github.com/kivy-garden/garden.zbarcam/blob/20171220/zbarcam/zbarcam.kv#L22

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值