This commit is contained in:
yumoqing 2021-06-30 14:42:33 +08:00
parent 335c17bd56
commit 7fdbf8bc76
3 changed files with 24 additions and 10 deletions

View File

@ -1,14 +1,15 @@
from kivy.utils import platform
import plyer
try:
#
# from android import activity
# get_rotation() failed module 'android.activity' has no attribute 'getWindowManager'
from plyer.platforms.android import activity
except:
print('android_rotation.py:mport ERROR')
print('android_rotation.py:import ERROR')
activity = None
ROTATION_0 = 0
ROTATION_90 = 1
ROTATION_180 = 2
ROTATION_270 = 3
def get_rotation():
try:
r = activity.getWindowManager().getDefaultDisplay().getRotation()

View File

@ -6,6 +6,8 @@ from kivy.uix.camera import Camera
from kivy.properties import NumericProperty
from kivy.event import EventDispatcher
from .android_rotation import *
if kivy.platform in [ 'win', 'linux', 'macosx' ]:
from PIL import ImageGrab
class ScreenWithMic(Micphone, EventDispatcher):
@ -26,13 +28,27 @@ if kivy.platform in [ 'win', 'linux', 'macosx' ]:
}
return d
VS={
ROTATION_0:270,
ROTATION_90:0,
ROTATION_180:90,
ROTATION_270:180,
}
class CameraWithMic(Micphone, Camera):
angle = NumericProperty(0)
def __init__(self, **kw):
super(CameraWithMic, self).__init__(**kw)
self.isAndroid = kivy.platform == 'android'
if self.isAndroid:
self.angle = -90
self.set_angle(-90)
def set_angle(self, angle):
self.angle = angle
def image_rotation(self):
if not self.isAndroid:
return
x = get_rotation()
self.angle = VS[x]
def get_image_data(self):
image = np.frombuffer(self.texture.pixels, dtype='uint8')
@ -41,6 +57,7 @@ class CameraWithMic(Micphone, Camera):
return imgdata
def get_fps_data(self, *args):
# self.image_rotation()
ad = super(CameraWithMic, self).get_fps_data()
vd = self.get_image_data()
d = {

View File

@ -131,16 +131,12 @@ class TwoSides(WidgetReady, BoxLayout):
pass
def on_afterswitch_landscape(self, *args):
print('twosides.py:Window.rotation=', Window.rotation,
Window.size)
pass
def on_beforeswitch_portrait(self, *args):
pass
def on_afterswitch_portrait(self, *args):
print('twosides.py:Window.rotation=', Window.rotation,
Window.size)
pass
def on_interactive(self, *args):