首页 文章

设置从IMG标签中的Cordova Camera Plugin检索的图像

提问于
浏览
1

我正在尝试使用Apache Cordova Camera API来显示从相机中检索到的图像 . 我正在接听相机电话,并且能够点击图片 . 我得到文件网址为

文件:///mnt/.....something.jpg

现在,我无法使用jQuery在现有的图像标记中设置此图像 .

我使用的代码是:

$("#img").attr("src", "data:image/jpeg;base64," + imageData);

其中imageData是摄像机成功回调的返回值 .

我正在使用的Cordova Image功能选项

destinationType = 0; sourceType = 1; encodingType = 0;

标签上没有图像 . 这可能是什么问题?

1 回答

  • 1

    这是一个关于它应该如何工作的快速示例:

    function changePhoto(){
            var cameraSuccess = function(imageURI){
                //add dummy param to disable caching
                var random = Math.floor(Math.random()*1000);
                var newImagePath = imageURI + "?dummy=" + random;
                $("#img").attr("src",newImagePath);
            };
            var cameraError = function(msg){
                alert(msg);
            };
    
            navigator.camera.getPicture( cameraSuccess, cameraError, { 
                quality: 50, 
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.PHOTOLIBRARY
            });
        },
    

相关问题