问题
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