[ 
https://issues.apache.org/jira/browse/CB-11692?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15427991#comment-15427991
 ] 

Mohammed Sadiq M C commented on CB-11692:
-----------------------------------------

[~vladimir.kotikov] Please find below code snippet used in my application. As I 
mentioned earlier, JPG images are getting attached but not PNG. Also I tried 
there is no reason for error received in _image.onerror_. 
{code}

$('#btnGallery').click(function () {
    getPhoto(navigator.camera.PictureSourceType.SAVEDPHOTOALBUM);
});

function getPhoto(source) {
    navigator.camera.getPicture(function (imageURI) { 
        addLoader();
        onPhotoURISuccess(imageURI);
    }, CameraFail, {
        quality: 35,
        destinationType: navigator.camera.DestinationType.FILE_URI,
        saveToPhotoAlbum: false,
        sourceType: source,
        allowEdit: false,
        targetWidth: 600,
        targetHeight: 800
    });
}

function onPhotoURISuccess(imageURI) {
  // converts the image to a 2d canvas
  canvasimage(imageURI);
}

function canvasimage(src) {
    var canvas = document.createElement("canvas");
    var ctx = canvas.getContext("2d");
    var imgdata = new Image;
    
    imgdata.onload = function () {
        canvas.width = this.width;
        canvas.height = this.height;
        ctx.drawImage(this, 0, 0);
        dataURL = canvas.toDataURL('image/jpeg');

        var blob = dataURItoBlob(dataURL);
        gotfilesystem(blob);
    }

     imgdata.onerror = function () {
         alert('error');
     }
    
    imgdata.src = src;
}

function dataURItoBlob(dataURI) {
    // convert base64/URLEncoded data component to raw binary data held in a 
string
    var byteString;
    if (dataURI.split(',')[0].indexOf('base64') >= 0)
        byteString = atob(dataURI.split(',')[1]);
    else
        byteString = unescape(dataURI.split(',')[1]);

    // separate out the mime component
    var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];

    // write the bytes of the string to a typed array
    var ia = new Uint8Array(byteString.length);
    for (var i = 0; i < byteString.length; i++) {
        ia[i] = byteString.charCodeAt(i);
    }

    return new Blob([ia], { type: mimeString });
}
.........
{code}

> Unable to load .png image from gallery
> --------------------------------------
>
>                 Key: CB-11692
>                 URL: https://issues.apache.org/jira/browse/CB-11692
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin Camera
>    Affects Versions: 1.2.0
>         Environment: Cordova Version: 5.0.0
> Installed Platform: wp8
> Plugins:
> cordova-plugin-camera 1.2.0 "Camera"
> cordova-plugin-file 3.0.0 "File"
> cordova-plugin-file-transfer 1.4.0 "File Transfer"
> cordova-plugin-whitelist 1.2.0 "Whitelist"
> cordova.plugins.diagnostic 1.1.0 "Diagnostic"
>            Reporter: Mohammed Sadiq M C
>              Labels: wfc, wp8
>
> I am blocked with image selection from gallery. I cant able to load the .png 
> image selected from gallery to the UI. Appreciating for the fix .



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to