7

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

1 Answers1

7

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);
Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Woah awesome. OK thanks. So is it possible to read these files again once they've been saved? – Ari Anastassiou Aug 22 '13 at 09:47
  • What's the point of saving them otherwise ;-) Storage has a method to open an input stream too and you can use EncodedImage.create(stream) to get an image object. – Shai Almog Aug 22 '13 at 15:14
  • Is this "local storage" something like the LocalStorage of a browser or is it actually persisting the image on the device? If latter, where will it be saved? Can I view it e.g. in the device' photo album or something? – Stacky Nov 17 '15 at 21:29
  • No to both. I can go into details but its a long explanation and moderators would "flip". Shortform: storage is permanent but when you uninstall an app its always removed with the uninstall. FileSystem "sometimes" does that and has a more elaborate hierarchy. – Shai Almog Nov 18 '15 at 03:35