Easy AS3 Print Canvas
About 18 months ago, I’d been looking for a decent way to circumvent AS3’s annoying BitmapData pixel size limit to easily produce print resolution generative stuff. According to livedocs:
In AIR 1.5 and Flash Player 10, the maximum size for a BitmapData object is 8,191 pixels in width or height, and the total number of pixels cannot exceed 16,777,215 pixels. (So, if a BitmapData object is 8,191 pixels wide, it can only be 2,048 pixels high.)
Keith Peters had the same problem, but there in the comments was a mention of this fantastic hack by Martin Rädlinger at formatlos. BitmapUnlimited does some clever hack thing to do with a GIF that somehow tricks the player to make bigger bitmaps. Works great too.
So in order to make print res bitmaps even easier, I’ve wrapped it in PrintCanvas, a simple little class of my own. Here’s how to use it:
1 2 3 4 5 6 7 8 9 10 11 12 | import tv.palmerama.display.PrintCanvas; import tv.palmerama.utils.CustomEvent; var printCanvas:PrintCanvas = new PrintCanvas(); printCanvas.addEventListener("PrintCanvas ready", onPrintCanvasReady); printCanvas.createPaperType("A2", 300, "landscape", 0xFFFF00); function onPrintCanvasReady(e:CustomEvent):void { addChild(new Bitmap(e.params.bmd)); printCanvas.saveImage("PNG", "PNG_test_image"); } |
So that creates an A2, 300dpi, yellow landscape canvas, adds it to the stage in a bitmap once it’s ready and saves it as a PNG. You can have a JPG too with quality setting, plus saveImage() returns its FileReference object in case you want to track progress etc. It can take a while.
Basically, you can have any size you want at any dpi. But beware memory issues! This eats it fast, so the A2 at 300dpi in this example could easily be a killer. That said, currently supported sizes from what I could find on Wikipedia are:
A0, A1, A2, A3, A4, A5, A6, A7, A8, Letter, Legal, Tabloid.
I couldn’t seem to find out much about standard American sizes beyond Letter and Legal (oddly, on the internet). Any help much appreciated.
One big drawback of BitmapDataUnlimited is that it can’t handle filters beyond the usual BMD size. EDIT: See Martin’s comment below. That saves me some work! I’m only really bothered as the look of the screen res images I was playing with a long time back played heavily on the use of glows. Maybe now I can get on with making pretty things again, this time big enough to go on the wall.
January 18th, 2010 by Addy P.
It's all about the experiments / r 'n' d, flash | 4 Comments »


you can apply your filter directly to the BitmapData via bitmap.applyFilter() … this should work.
cheers Martin
um wow!, had no idea there would ever be a way around the size limits. Your work into making filters work sounds promising, all the best with that, I would love to print something huge res from this, know the perfect spot
I am not in the US so I don’t know much about paper sizes there, I found this list though;
http://www.printernational.org/american-paper-sizes.php
[...] next I need to get this onto my PrintCanvas and try using different images and rotations for grey levels – like you would with perlin noise – [...]
[...] some nice new features into PrintCanvas. It’s all very well having a massive BitmapData for print, but it’d be nice to see what [...]