phonegap camera not loading image into <img> tag

本小妞迷上赌 提交于 2019-12-23 12:59:26

问题


I am trying to use the navigator.camera object to capture an image and push it into an img tag. I am doing what the demo says in the phonegap docs like this:

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 though, I get a broken link in the imageForTask . This is what the source says: data:image/jpeg;base64,content://media/external/images/media/325. Does anyone know why this wouldn't work? I have been wrestling with this for awhile. Thanks!

-Geoff


回答1:


The default destinationType has been changed from DATA_URL to FILE_URI. If you add an option:

destinationType : Camera.DestinationType.DATA_URL

to the options you pass to get picture you will be able to set it as base64 encoded data.

http://docs.phonegap.com/en/1.6.1/cordova_camera_camera.md.html#cameraOptions_options




回答2:


content://media/external/images/media/325 is the path to an image, not its actual binary data. You'll need to use the filesystem API to get the contents of the file, base64 encode it, and use that.



来源:https://stackoverflow.com/questions/10419383/phonegap-camera-not-loading-image-into-img-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!