在代号一个项目中本地保存图像 [英] Saving an Image Locally in Codename One Project

查看:50
本文介绍了在代号一个项目中本地保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照该视频中的创建相机捕获页面的教程进行操作: http:// www.youtube.com/watch?v=nF4eqzVcsic

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) {
        }
    }

}

我看了一下CameraDemo应用程序,但似乎找不到要保存的文件。

I had a look at the CameraDemo application, but can't seem to locate any files being saved.

我基本上只是希望将拍摄的任何照片保存在src文件夹中。

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

任何帮助将不胜感激。
Ari

Any help would be greatly appreciated. Ari

推荐答案

src文件夹在您的设备上不存在,并且您无权访问应用程序文件夹(存储本机二进制文件的位置),否则您就可以在可能安装病毒的设备上更改应用程序。

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.

变量 i 是一个临时文件URL,您可以在PC / Mac上看到它。您应该将其复制到本地文件或本地存储中。

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.

您可以使用 FileSystemStorage ,然后可以使用相同的类(例如,在应用程序主目录中)存储它,也可以使用 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);

这篇关于在代号一个项目中本地保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆