Saving an image locally in Codename One project

I followed the tutorial on creating a camera capture page in this video: http://www.youtube.com/watch?v=nF4eqzVcsic

So my code at the moment looks like this:

protected void onCamera_CaptureButtonAction(Component c, ActionEvent event) { String i = Capture.capturePhoto(); if (i != null) { try { Image img = Image.createImage(i).scaledHeight(500); findCameraLabel().setIcon(img); } catch (Exception ex) { } } } 

I looked at the CameraDemo application, but cannot find the files that will be saved.

Basically, I want any snapshots to be saved in the src folder.

Any help would be greatly appreciated. Ari

+6
source share
1 answer

The src folder does not exist on your device, and you do not have access to the "application folder" (where your own binary files are stored), otherwise you can change your application on the device, potentially installing a virus.

The variable i in your example is the temporary URL of the file that you can see on your PC / Mac. You must copy it to a local file or local storage.

You can open the input stream for an image using FileSystemStorage , you can save it using the same class (for example, in the application’s home directory), or you can use the Storage class to save the image somewhere.

eg. you can copy the image to local storage as such:

 InputStream stream = FileSystemStorage.getInstance().openInputStream(i); OutputStream out = Storage.getInstance().createOutputStream("MyImage"); Util.copy(stream, out); Util.cleanup(stream); Util.cleanup(out); 
+7
source

Source: https://habr.com/ru/post/952221/


All Articles