2012-09-01 15 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

[Benzer soru] (http://stackoverflow.com/q/6690571/1050058) –

cevap

2

PhoneGap 2.0.0 camera object'u kullanmalısınız. Belgeler tam bir fotoğraf çekimi örneği sağlar.

Ayrıca navigator.camera.getPicture(cameraSuccess, cameraError, [ cameraOptions ]); fotoğraf makinesini kullanarak bir fotoğraf çeker veya aygıtın albümünden bir fotoğraf alır. Görüntü, base64 kodlu bir String veya bir görüntü dosyasının URI'si olarak döndürülür.

Umarım bu yardımcı olur.

İlgili konular