我试图使用buildozer,plyer和kivy来编码apk来捕获Android设备上的照片。使用take_picture()
方法遇到很多麻烦。最初我使用的是Camera().take_picture()
,但在查看源代码后,我决定绕过Cameras多平台功能并使用AndroidCamera()
类代替。我的代码如下(对不起批量):
from kivy.app import App
from kivy.uix.label import Label
#from kivy.facades.camera import Camera
from plyer.platforms.android.camera import AndroidCamera
import datetime
class CameraApp(App):
def build(self):
self.label =Label(text='Camera Test')
return self.label
def on_start(self):
self.take_shot()
def take_shot(self):
IMAGEPATH='DCIM/Camera'
time = datetime.datetime.now().strftime('%d-%m-%Y_%H:%M')
self.file_name='{0}/IMG_{1}.jpg'.format(IMAGEPATH,time)
try:
AndroidCamera().take_picture(filename=self.file_name,
on_complete=self.complete_callback())
self.label.text=(self.file_name +str('\nCaptured'))
except:
self.label.text=(self.file_name+str('\nFailed to Capture'))
def complete_callback(self):
return False
def on_pause(self):
return True
def on_resume(self):
pass
if __name__=='__main__':
CameraApp().run()
当我在Android上运行 此代码 时,应用程序崩溃了,但是当我使用标准Camera().take_picture()
时,代码会捕获异常,但仍然没有照片。
我的问题是,任何人都可以看到我出错的地方吗?
我很自然地在usb调试中得到了这个回溯,虽然它意味着我无法解决:
Traceback (most recent call last):
File "/usr/bin/buildozer", line 11, in <module>
sys.exit(main())
File "/usr/lib/python3.4/site-packages/buildozer/scripts/client.py", line 13, in main
Buildozer().run_command(sys.argv[1:])
File "/usr/lib/python3.4/site-packages/buildozer/__init__.py", line 1058, in run_command
self.target.run_commands(args)
File "/usr/lib/python3.4/site-packages/buildozer/target.py", line 91, in run_commands
func(args)
File "/usr/lib/python3.4/site-packages/buildozer/targets/android.py", line 973, in cmd_logcat
show_output=True)
File "/usr/lib/python3.4/site-packages/buildozer/__init__.py", line 314, in cmd
stdout.write(chunk.decode('utf-8'))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 107: invalid start byte