Closed GoogleCodeExporter closed 9 years ago
You must append the canvas element to the DOM tree when you use FlashCanvas
library. For example, the following code works with FlashCanvas.
var canvas = document.createElement("canvas");
// Append the canvas element to the DOM tree
document.body.appendChild(canvas);
if (typeof FlashCanvas != "undefined") {
FlashCanvas.initElement(canvas);
}
canvas.width = 100;
canvas.height = 100;
// Hide the canvas
canvas.style.display = "none";
var ctx = canvas.getContext("2d");
ctx.fillStyle = "blue";
ctx.fillRect(0, 0, 10, 10);
var imageData = ctx.getImageData(0, 0, 10, 10);
alert(imageData.data);
Does this code solve your problem? If everything is OK, I'll close this issue.
Original comment by revu...@gmail.com
on 17 Nov 2010 at 2:41
Thanks for the quick reply!
Yes, that works. But the problem is we need an "off screen" canvas that we can
draw to without displaying it on the page, then using getImageData and
putImageData, transfer to an "on screen" canvas. I tried:
offcanvas.style.visibility = 'hidden';
document.body.appendChild(offcanvas);
But this causes the same error.
Any other ideas?
BTW FlashCanvas is great, nice work!
Original comment by Radishwo...@gmail.com
on 17 Nov 2010 at 3:39
[deleted comment]
Uh... I think I showed you an example of "off screen" canvas. My code contains
the following line:
// Hide the canvas
canvas.style.display = "none";
If you comment out the line, a small blue square will appear on the screen.
Note that we cannot hide a canvas element before initializing the element,
though I don't know the exact reason.
Original comment by revu...@gmail.com
on 17 Nov 2010 at 4:51
Oops, my bad, I missed that line of code. Sorry :-)
Works great, thanks for the help.
OK to close this issue.
Original comment by Radishwo...@gmail.com
on 17 Nov 2010 at 3:53
Original comment by revu...@gmail.com
on 17 Nov 2010 at 11:32
Original issue reported on code.google.com by
Radishwo...@gmail.com
on 17 Nov 2010 at 1:03