【问题标题】:Taking photos with a phonegap/cordova application and convert into base64image before upload to them to the server使用 phonegap/cordova 应用程序拍照并转换为 base64image,然后再上传到服务器
【发布时间】:2018-08-12 11:15:56
【问题描述】:

在获取存储在 catch 中的图像文件位置后,我正在使用 cordova 插件从相机捕获图像 文件补丁是

    file:///storage/emulated/0/Android/data/mm/catche/54251.jpg 

我想转换成 base64 图像文件。我怎样才能得到 base64 字符串。

<button class="hide_file" type="button" onclick="capturePhotoWithFile();"></button>
    function capturePhotoWithFile() {
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        quality: 30, 
        destinationType: Camera.DestinationType.FILE_URI,
        sourceType: Camera.PictureSourceType.Camera
    });
}

function onPhotoURISuccess(imageURI) {
$('#Image1').attr("src",imageURI);// getting file:///storage/emulated/0/Android/data/mm/catche/54251.jpg 

  }

我想将 Image URI 转换为 base64 图像文件。如何获取 base64 字符串。

【问题讨论】:

    标签: javascript java phonegap-plugins phonegap


    【解决方案1】:

    请查看文档。 Cordova

    根据相机配置的destinationType返回各自的图像格式。

    今后获取 base64 图像的 destinationType 应为 DATA_URL 并在成功时回调。

    function onSuccess(imageData) {
    var image = document.getElementById('myImage');
    image.src = "data:image/jpeg;base64," + imageData;
    

    }

    【讨论】:

    • 我正在获取数据:image/jpeg;base64,file:///storage/emulated/0/Android/data/mm/catch/54251.jpg 文件不是正确的图像 base61 字符串
    • 我的几个问题,您是否已将相机选项的 DestinationType 更改为 DATA_URL。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多