Saving an Image Locally in Codename One Project

随声附和 提交于 2019-12-19 02:35:09

问题


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:


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);


来源:https://stackoverflow.com/questions/18362854/saving-an-image-locally-in-codename-one-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!