如何获得数码相机以保存图像?

时间:2019-04-17 13:51:23

标签: python android-camera buildozer

当我在华为Android手机上运行我的应用程序,而普莱尔相机打开相机应用程序后,拍照后,即使重新启动手机,图像也不在其目录中。

当我使用Image.open(“ / storage / emulated / 0 / Download / .... png”)时,它可以工作,但是在camera._take_picture()中将其设置为文件名时,该文件不是保存成功。我尝试将uri编辑为以“ content://”开头,然后没有任何内容,但最终没有任何效果。

有没有办法解决这个问题?

    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)

稍后,运行代码OGImg = Image.open(“ {}。png” .format(File)),它应该做的是识别出那里有一个图像并打开它。我正在使用python 3.6,buildozer以及所有最新的Android API和NDK。

0 个答案:

没有答案