【问题标题】:How to display an image captured with cordova-plugin-media-capture如何显示使用 cordova-plugin-media-capture 捕获的图像
【发布时间】:2018-04-04 01:46:23
【问题描述】:

我正在使用this plugin,它允许我使用我的 Android 手机拍摄图像。

现在我应该如何显示刚刚在我的应用中捕获的图像?以下没有奏效。它说:“TypeError:无法在‘FileReader’上执行‘readAsDataURL’:参数1不是‘Blob’类型。”

function capturePhoto(){
    navigator.device.capture.captureImage(
        file=>{
            getBase64(file).then(b64=>{
                document.getElementById('fsPhotoI').src=b64;
            }).catch(e=>alert(e));
        },
        error=>{alert(error);},
        {limit:1}
    );
}

function getBase64(f) {
    return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.readAsDataURL(f);
        reader.onload = () => resolve(reader.result);
        reader.onerror = error => reject(error);
    });
}

【问题讨论】:

    标签: javascript cordova android-camera cordova-plugins filereader


    【解决方案1】:

    我解决了:

    function capturePhoto(){
        navigator.device.capture.captureImage(
            file=>{
                document.getElementById('fsPhotoI').src=file[0].fullPath;
            },
            e=>{alert(JSON.stringify(e));},
            {limit:1}
        );
    }
    

    我忽略的一件事是返回的“文件”变量是一个数组而不是单个文件,即使只捕获一张图像也是如此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多