簡體   English   中英

如何顯示使用cordova-plugin-media-capture捕獲的圖像

[英]How to display an image captured with cordova-plugin-media-capture

我正在使用這個插件,它允許我用我的 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);
    });
}

我解決了:

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

我忽略的一件事是,返回的“文件”變量是一個數組而不是單個文件,即使只捕獲了一張圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM