Cordova - Reading Large Image corrupts image

后端 未结 1 1862
小蘑菇
小蘑菇 2020-12-21 12:53

I am using the image-picker (cordova-imagePicker) plugin in order to get images from gallery and upload them to a server.

I am using Cordova 6.1.1 with Android platf

相关标签:
1条回答
  • 2020-12-21 13:27

    I found your question while searching for a solution for a similar problem. DataURL's of large images from camera would show up when used as the source of an image but the same image got corrupted when I use fileReader.readAsDataURL.

    I've been able to bypass the problem by using fileReader.readAsBinaryData instead of fileReader.readAsDataURL and then turning the binarystring into a dataURL.

    window.resolveLocalFileSystemURL(imageUri, function done(fileEntry) {
        fileEntry.file(function (fileObj) {
            var image = new Image();
            var reader = new FileReader();
            reader.onloadend = function (e) {
                image.src = "data:image/jpeg;base64," + window.btoa(e.target.result)
            }
            reader.readAsBinaryString(fileObj);
        }
    } 
    

    Hopefully this helps you to find a workaround of your own.

    0 讨论(0)
提交回复
热议问题