2012-09-01 96 views
5
<script type="text/javascript" charset="utf-8"> 



var pictureSource; // Picture source 

var destinationType; // Sets the format of returned value 

// Wait for PhoneGap to connect with the device 


document.addEventListener("deviceready", onDeviceReady, false); 


// PhoneGap is ready to be used! 

function onDeviceReady() 

{ 


    pictureSource = navigator.camera.PictureSourceType; 

    destinationType = navigator.camera.DestinationType; 


} 

function capturePhoto() { 

    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 25, destinationType: 
Camera.DestinationType.FILE_URI }); 

} 

function onPhotoURISuccess(imageURI) { 

    createFileEntry(imageURI); 
} 

function createFileEntry(imageURI) { 

    window.resolveLocalFileSystemURI(imageURI, copyPhoto, fail);  
} 

function copyPhoto(fileEntry) { 

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) { 
     fileSys.root.getDirectory("photos", {create: true, exclusive: false}, 

function(dir) { 

    fileEntry.copyTo(dir, "file.jpg", onCopySuccess, fail); 

      }, fail); 
    }, fail); 
} 

function onCopySuccess(entry) { 

    console.log(entry.fullPath) 
} 

function fail(error) { 

    console.log(error.code); 
} 


    </script> 
+0

[Similar questions](http://stackoverflow.com/q/6690571/1050058) –

回答

2

您應該使用PhoneGap 2.0.0 camera object。該文檔提供了一個完整的照片捕獲示例。

此外,navigator.camera.getPicture(cameraSuccess, cameraError, [ cameraOptions ]);使用相機拍攝照片或從設備相冊中檢索照片。該圖像作爲base64編碼的字符串返回或作爲圖像文件的URI返回。

我希望這會有所幫助。

相關問題