How to get plyer camera to save images?

独自空忆成欢 提交于 2020-01-06 14:33:26

问题


When I run my app on my Huawei Android phone, and the plyer camera opens the camera app, after taking the photo, the image is not in its directory, even after the phone being restarted.

When I use Image.open("/storage/emulated/0/Download/....png"), it works, but when setting that as the filename in camera._take_picture(), the file isn't saved successfully. I tried editing the uri to start with 'content://' and then with nothing, but in the end nothing works.

Is there a way to fix this?

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

            context = PythonActivity.mActivity
            intent = Intent()
            uri = 'content://{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}.png'.format(File)
            im.save(outfile, "PNG")
        except Exception as e:
            Logger.error(str(e))
            self.error = str(e)

    def update(self, *args):
        global Results, Resulta, File
        self.my_camera = MyCamera()
        File = "/storage/emulated/0/Download/SpeedBot"
        self.my_camera._take_picture(self.on_success_shot, self.image_path)

Later on in the code, OGImg = Image.open("{}.png".format(File)), is run, and what it should do is recognise that there is an image there and open it. I'm using python 3.6, buildozer, and all the latest Android API's and NDK's.

来源:https://stackoverflow.com/questions/55729126/how-to-get-plyer-camera-to-save-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!