CameraRoll image to canvas using Phonegap

2020-06-25 05:06发布

问题:

I'm trying (aka getting mad) to get an image from camera roll/album's iphone and putting onto a canvas over phonegap, and specifically, using the Camera Plugin but I can't do it. Here is the function that should show the image in an tag, but I want to put it in canvas due to edit and then save it:

function onPhotoURISuccess(imageURI) {
      var largeImage = document.getElementById('largeImage');
      largeImage.style.display = 'block';
      largeImage.src = imageURI;
}

Any ideas?

Thanks in advance, DGM.-

回答1:

And this is the solution : )

function onPhotoURISuccess(imageURI) {
    var cambas = document.getElementById('canvas_1');
    var ctx = cambas.getContext("2d");
    var imagen = new Image();
    imagen.onload = function(){
        cambas.width = imagen.width;
        cambas.height = imagen.height;
        ctx.drawImage(imagen, 0, 0, imagen.width, imagen.height);
    }

    imagen.src = imageURI;
}