-1

Is there a way to read transparent pixels from a picture using javascript, but without canvas?

  • You can create a hidden canvas and do it there – MightyPork Aug 07 '14 at 16:21
  • You mean without using getImageData. You can use getImageDate with a memory canvas, see http://stackoverflow.com/questions/10754661/javascript-getting-imagedata-without-canvas but as getImageData is a method of canvas, you will need to have a canvas of some sort. – John Powell Aug 07 '14 at 16:21

1 Answers1

0

Would an in memory canvas be okay for you?

In that case you can do:

var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var img = document.getElementById('id');
ctx.drawImage(img, 0, 0);
var data = ctx.getImageData(0, 0, img.width, img.height).data;

for (var i = 0 ; i < data.length ; i += 4) {
    if(data[i+3] == 0) {
        // do something with this pixel
    }
}
kpj
  • 21
  • 1
  • 3
  • As in http://stackoverflow.com/questions/10754661/javascript-getting-imagedata-without-canvas – John Powell Aug 07 '14 at 16:27
  • True, the pixel manipulation can also be seen in http://stackoverflow.com/questions/667045/getpixel-from-html-canvas – kpj Aug 07 '14 at 17:01