Phone camera does not load image in <img> tag
I am trying to use the navigator.camera object to capture an image and embed it in the img tag. I do what the demo says on the phone, for example:
if(navigator.camera) {
navigator.camera.getPicture(function(imageData){
var $image = document.getElementById('imageForTask');
image.src = "data:image/jpeg;base64," + imageData;
console.log(imageData);
}, null, {sourceType:1, quality: 50});
} else {
alert("Camera not supported on this device.");
}
When I do this, I get a broken link in imageForTask. Says the source: data:image/jpeg;base64,content://media/external/images/media/325. Does anyone know why this will not work? I struggled with this for a while. Thank!
-Geoff
+3
2 answers
The default destination type has been changed from DATA_URL to FILE_URI. If you add an option:
destinationType : Camera.DestinationType.DATA_URL
to the parameters that you pass in order to get the image, you can set it as base64 encoded data.
http://docs.phonegap.com/en/1.6.1/cordova_camera_camera.md.html#cameraOptions_options
+4