在Worklight应用程序中将图像保存到SD卡 [英] Saving image to SD Card in a Worklight application

查看:80
本文介绍了在Worklight应用程序中将图像保存到SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了Worklight应用程序,并将其添加到了Android环境中.此应用程序具有使用设备相机拍摄照片的按钮,以及HTML中的img标签,用于显示捕获的照片.

I have created a Worklight application and added to it the Android environment. This application has a button to take a photo using the device camera, and an img tag in the HTML which displays the captured photo.

我遵循了 PhoneGap Camera API .

现在,我正在尝试将该图像存储到SD卡中,但操作失败.我的

Now I am trying to store that image into the SD Card but fail doing so. my

我将代码更改如下:

function takeimage() {
// Retrieve image file location from specified source
navigator.camera.getPicture(getImageURI, function(message) {
alert('Image Capture Failed');
}, {
quality : 40,
destinationType : Camera.DestinationType.FILE_URI
});
}
function getImageURI(imageURI) {

var gotFileEntry = function(fileEntry) { 
    var img=document.getElementById("thisImage");
    img.style.visiblity="visible";
    img.style.display="block";
    img.src=imageURI;
        alert("got image file entry: " + fileEntry.fullPath); 
        var gotFileSystem = function(fileSystem){ 
            // copy the file 
            fileEntry.moveTo(fileSystem.root, "pic.jpg", null, null); 
       }; 
        // get file system to copy or move image file to 
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fsFail); 
    }; 
    //resolve file system for image  
    window.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail); 
}
//file system fail 
function fsFail(error) { 
    alert("failed with error code: " + error.code); 
}

moveTo方法外,其他所有功能均正常(捕获图像和应用程序缓存文件夹中可用的图像). fileEntry.moveTo(fileSystem.root, "pic.jpg", null, null); 我将fileSystem.root置于警报中,并且得到了Object object.因此,该文件夹位置无法移动该图像(而且我认为这是真正的问题).

Everything working fine(capturing image and image available in app cache folder) except moveTo method. fileEntry.moveTo(fileSystem.root, "pic.jpg", null, null); I put fileSystem.root in alert and I am getting Object object. So the folder location is not available to move that image(And I think its the real problem).

推荐答案

实际上,这与Worklight无关.

This, in fact, has got nothing to do with Worklight.

由于您已经在使用Apache Cordova访问设备的相机来拍摄照片,因此您还应该使用它来将图像文件存储到设备的SD卡中.

Since you are already using Apache Cordova to access the device's camera to snap a photo, you should also use it to store the image file to the device's SD Card.

以下是一些SO问题,可为您指出正确的解决方案:

Here are a couple of SO questions to point you to the right solution for you:

  • How to move captured image in PhoneGap to a folder in sdcard
  • Capturing and storing a picture taken with the Camera into a local database / PhoneGap / Cordova / iOS

注释#1::您指向PhoneGap Camera API的链接指向v1.0. Worklight 5.0.6.x使用PhoneGap 2.3.0,因此请确保

Note #1: your link to the PhoneGap Camera API points to v1.0. Worklight 5.0.6.x uses PhoneGap 2.3.0, so be sure to use the correct API version.

注意#2::通过将以下行添加到android.manifest文件中,确保您已添加了写入SD卡的权限:

Note #2: make sure you have added permission to write to the SD Card by adding the below line to the android.manifest file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

注意#3::如果上述#2不够用,请尝试按以下方式获取SD卡的位置:

Note #3: in case #2 above is not enough, try getting the SD Card location like this:

File sdDir = Environment.getExternalStorageDirectory();

这篇关于在Worklight应用程序中将图像保存到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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