phonegap相机未将图像加载到< img>标签 [英] phonegap camera not loading image into <img> tag
问题描述
我想使用navigator.camera对象捕获图像并将其推入img标签。我在demogap docs中做这样的演示:
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(此设备上不支持相机。
}
当我这样做的时候,我得到一个损坏的链接在imageForTask。这是源说: data:image / jpeg; base64,content:// media / external / images / media / 325
。有人知道为什么这不会工作吗?我一直在摔跤这一会儿。谢谢!
-Geoff
从DATA_URL到FILE_URI。如果您添加选项:
destinationType:Camera.DestinationType.DATA_URL
pre>
到您传递的选项以获得图片,您将能够将其设置为base64编码数据。
http://docs.phonegap.com/en/1.6。 1 / cordova_camera_camera.md.html#cameraOptions_options
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
解决方案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
这篇关于phonegap相机未将图像加载到< img>标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!