gpt4 book ai didi

android - Kivy Plyer 相机

转载 作者:搜寻专家 更新时间:2023-11-01 07:49:35 25 4
gpt4 key购买 nike

我尝试使用 Plyer Camera 制作小应用程序。

def take_shot(self, *args):
self.filepath = IMAGE_PATH
self.time = datetime.now().strftime("%Y%m%d_%H%M%S%f")
self.filename = '{0}/IMG_{1}.jpg'.format(self.filepath, self.time)
try:
camera.take_picture(filename=self.filename, on_complete=self.complete_callback)
except NotImplementedError:
self.camera_status = 'Camera is not implemented for your platform'

def complete_callback(self):
try:
im = Image.open(self.filename)
im.thumbnail(Window.size)
outfile = '{0}/IMG_{1}-thumbnail.jpg'.format(self.filepath, self.time)
im.save(outfile, "JPEG")
except Exception as e:
self.error = str(e)

return False

但是:

  1. 当我拍照时,照片在设备的相册中不可见,只有在设备重置后才会出现。
  2. 未调用函数 complete_callback。

最佳答案

所以,我终于解决了画廊的问题,现在我的代码如下所示:

def take_shot(self, *args):
self.time = datetime.now().strftime("%Y%m%d_%H%M%S%f")
filename = '{0}/IMG_{1}.jpg'.format(IMAGE_PATH, self.time)
try:
camera.take_picture(filename=filename, on_complete=self.complete_callback)
except NotImplementedError:
self.camera_status = 'Camera is not implemented for your platform'

def complete_callback(self, filename):
try:
Intent = autoclass('android.content.Intent')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
Uri = autoclass('android.net.Uri')

# Push photo into gallery
context = PythonActivity.mActivity
intent = Intent()
uri = 'file://{0}'.format(filename)
intent.setAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)
intent.setData(Uri.parse(uri))
context.sendBroadcast(intent)

im = Image.open(filename)
im.thumbnail(Window.size)
outfile = '{0}/IMG_{1}.jpg'.format(THUMBNAIL_PATH, self.time)
im.save(outfile, "JPEG")
except Exception as e:
Logger.error(str(e))
self.error = str(e)

return False

我希望这对某人有帮助。

关于android - Kivy Plyer 相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36912975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com