Skip to content

Instantly share code, notes, and snippets.

@timkim
Created May 15, 2012 19:44
Show Gist options
  • Save timkim/2704508 to your computer and use it in GitHub Desktop.
Save timkim/2704508 to your computer and use it in GitHub Desktop.
Short example of how to get photo from PhoneGap Camera to canvas
// Note: have not tested this - but I think it should work!
function cameraWin(picture){
var theCanvas = document.getElementById('theCanvas');
var ctx = theCanvas.getContext('2d');
var theImage = new Image();
theImage.src = "data:image/jpeg;base64,"+picture;
ctx.drawImage(theImage, 0, 0);
}
function cameraFail(){
alert('camera dead');
}
function takePicture(){
navigator.camera.getPicture(cameraWin, cameraFail, {quality: 50, destinationType: Camera.DestinationType.DATA_URL});
}
@Beefsteve
Copy link

It does not work for me. Only other thing I need is the canvas, right?

It does not display the image on the canvas :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment