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 from kivy.utils import platform
import plyer import plyer
try: try:
#
# from android import activity
# get_rotation() failed module 'android.activity' has no attribute 'getWindowManager'
from plyer.platforms.android import activity from plyer.platforms.android import activity
except: except:
print('android_rotation.py:mport ERROR') print('android_rotation.py:import ERROR')
activity = None activity = None
ROTATION_0 = 0
ROTATION_90 = 1
ROTATION_180 = 2
ROTATION_270 = 3
def get_rotation(): def get_rotation():
try: try:
r = activity.getWindowManager().getDefaultDisplay().getRotation() r = activity.getWindowManager().getDefaultDisplay().getRotation()

View File

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

View File

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