I noticed a strange problem with getImageData ; image transparency is apparently ignored when receiving image data.
Since any image must be drawn on canvas before its data can be retrieved, I assumed that this is a problem with an opaque canvas . But I was wrong, since using canvas as an argument in drawImage supports transparency.
This is how I uploaded the image;
var load_image = function(name, url, holder, callback) { var img = new Image(); img.src = url; img.addEventListener('load', function(e) { var canvas = make_canvas(e.target.width, e.target.height); var ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(e.target, 0, 0); holder[name] = {canvas: canvas, ctx: ctx}; delete e.target; callback.call(); }, false); };
callback is just a drawing function that calls draw_image to draw an image.
Normal version;
var draw_image = function(ctx, img, sx, sy, w, h, dx, dy) { ctx.drawImage(img.canvas, sx, sy, w, h, dx, dy, w, h); };
It just takes the canvas as an argument for drawImage , and the result will be the same as when maintaining transparency. An example .
Version of image data;
var draw_image = function(ctx, img, sx, sy, w, h, dx, dy) { var imagedata = img.ctx.getImageData(sx, sy, w, h); ctx.putImageData(imagedata, dx, dy); };
This one gets the image data of the required rectangle from the same canvas as in the regular version, and puts the image data on the canvas that I want to draw. I believe that transparency should be supported, but it is not. An example . (This is a Dropbox link due to the origin-clean flag.)
Am I mistaken in believing that transparency should be supported with getImageData ? Or am I using it incorrectly?
In any case, the help would be really appreciated.