Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving an Image Locally in Codename One Project

Tags:

codenameone

I've followed the tutorial of 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 had a look at the CameraDemo application, but can't seem to locate any files being saved.

I basically just want any pictures taken to be saved in the src folder.

Any help would be greatly appreciated. Ari

like image 600
Ari Anastassiou Avatar asked Aug 21 '13 16:08

Ari Anastassiou


1 Answers

The src folder doesn't exist on your device and you don't have access to the "application folder" (where the native binaries are stored) otherwise you would be able to change your application on the device potentially installing a virus.

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

You can open an input stream to the image using FileSystemStorage, you can then store it using that same class (e.g. in the application home directory) or you can use the Storage class to save the image somewhere.

E.g. you can copy 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);
like image 200
Shai Almog Avatar answered Oct 20 '22 16:10

Shai Almog