0

如何使用 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. 我怎样才能让它出现在移动图库中

4

1 回答 1

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 });         
}
于 2013-04-25T06:54:48.417 回答