使用phonegap将图像保存到图库中

时间:2012-08-27 00:20:44

标签: android cordova

如何使用android phonegap将图像保存到手机图库?

我试过这段代码:

   function save(){
document.addEventListener("deviceready", onDeviceReady, false);
}



// PhoneGap is ready
//
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    fileSystem.root.getFile("pic.jpg", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
console.log(fileEntry.fullPath);
    fileEntry.createWriter(gotFileWriter, fail);
}

function gotFileWriter(writer) {
    var photo = document.getElementById("dwnldImg");
    writer.write(photo.value);
}

但它将图像保存到我的项目目录file:///data/data/pack.name/pic.jpg。 如何让它出现在移动图库中

1 个答案:

答案 0 :(得分:1)

尝试使用:

function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string

    navigator.camera.getPicture(onPhotoDataSuccess, onFail,{
        quality : 25, 
        destinationType : Camera.DestinationType.FILE_URI, 
        sourceType : Camera.PictureSourceType.CAMERA, 
        allowEdit : true,
        encodingType: Camera.EncodingType.JPEG,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: true });         
}