Main Contents

Flash BitmapData’s 2880 px Limit Workaround

November 6, 2007

Problem:
We were developing a specialized application for a client. This application should be able to take an image template and allow users to customize (move/crop pictures, add message, etc.). To produce a good enough resolution acceptable for printing the application needs to handle templates as large as 2138×3038 pixels. Adobe Flash limits developers from creating BitmapData with width or height larger than 2880 pixels. Bad news. Try creating a Bitmap greater than the specified limit and you’ll get this error:

ArgumentError: Error #2015: Invalid BitmapData.

This will work:
var ValidBitmapData:BitmapData = new BitmapData(2880, 2880);

This won’t:
var InvalidBitmapData:BitmapData = new BitmapData(3000, 3000);

According to www.adobe.com:
The maximum dimensions of a bitmap in Flash Player is limited to 2880 pixels in either direction (width or height). If you attempt to create a BitmapData instance that is larger than this restriction, the Bitmap will not be created. This limit is in place to keep people from creating Flash movies that gobble up the client’s RAM. A bitmap that is 2880 x 2880 pixels, will use roughly 32MB of RAM.

This restriction becomes more and more useless as computer hardware becomes more and more capable.

Solution:
The trick is to “kidnap” a BitmapData object from a loaded image with dimension over the limit of 2880 pixels (Which flash allows. Huh! Yes Flash can actually handle bitmaps larger the the limit. It just doesn’t let you create one.).

It’s simple. Create a dummy image with the dimension you need. Save it and make it accessible to Flash. Dynamically load it using ActionScript. And take the loader object’s BitmapData object. That’s why I termed it “kidnap”. We are actually just taking the child of the parent object(loader object), which is the BitmapData, and use it like we build it ourselves.


// 1. Create an image loader and
var DummyImageLoader:Loader = new Loader;

// 2. Assign a function to “kidnap” the BitmapData object
DummyImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, DummyImageOnComplete);

// 3. Load the image with the preferred dimension
var DummyImageRequest:URLRequest = new URLRequest(“dummy_image.jpg”);
DummyImageLoader.load(DummyImageRequest);

function DummyImageOnComplete(evt:Event):void
{
var DummyImageBitmap = Bitmap(DummyImageLoader.content);
// “kidnap” the BitmapData object
var ValidBitmapData:BitmapData = DummyImageBitmap.bitmapData;

// you can now use ValidBitmapData to draw any element larger than 2880×2880
}

This will then allow you to use ValidBitmapData as you would have when you used this line:

var InvalidBitmapData:BitmapData = new BitmapData(3000, 3000);

Only this time it works.

Files: bitmapdata_workaround.zip

Source:
Original Solution (I believe nobody have used this workaround before.)

Note:
If the required BitmapData dimension varies too often you could generate the image dynamically. In our site we used a PHP script utilizing GD library to create the dummy images. Calling the script like this: dummy_jpeg.php?w=3000&h=3000 where w is the width and h the hieght in pixels.

Filed under: ActionScript | Comments (20)
Related Links:

20 Comments

  1. Trond Olsen January 12, 2008 @ 9:14 pm

    Nice trick. :)

    Client side handling of this would be nice if there where some way to trick the Loader into retrieving base64 encoded data from a data: URI. Then it should be possible to generate an “fake” bitmap and encode it in PNG with a rewritten dom.Adobe.images.PNGEncoder.

  2. Trond Olsen January 12, 2008 @ 10:44 pm

    Did some testing onloader.loadBytes(). Seems that too is limited to 2880 pixels.

    A modified com.adobe.imges.PNGEncoder is available at http://www.the-cluster.org/files/PNGEmptyEncoder.as if anyone want to give it a try. It takes as parameters width, height, hasAlpha and fillColor and returns a compressed PNG image (just a few ks for a large bitmap).

  3. Tom Krcha January 30, 2008 @ 9:55 pm

    Another trick:
    This kidnap trick works only with loaded bitmapData. But what if you snapshot bitmapData from your flash application. Then it can be whatever size.

    My trick is to make tiles. Just divide the actual bitmap into 4 or more tiles. Then you get 4 bitmapData – each with max. size limited by Flash Player. This allows you to work with bitmaps larger than limit – etc. 12 Mpx.

    My usage: I am working on drawing app. I need to allow users to create bitmaps larger than limit. So I cut bitmap into tiles – this makes me few BitmapData instances, I send this instances to server and here we go!

  4. Alan Owen February 7, 2008 @ 8:44 am

    Really great workaround; it sucks that developers get ‘hand-held’ by default with respect to making BMPdata objects – so thanks for sharing this tip

  5. Alan Owen February 7, 2008 @ 11:52 am

    …Run into a new limit – 4080px square, using BitmapData.draw() method :(

    Try .draw()ing an asset 5000px square into Bitmap data successfully created using this nifty workaround – the target is truncated after 4080px by width or height – looks like I can’t avoid bitmap tiling any longer *sighs*

  6. Trond Olsen February 15, 2008 @ 2:36 am

    Only problem might be seams between the tiles if there’s some filtering applied to the image?

  7. BitmapDataUnlimited / formatlos May 28, 2008 @ 2:41 pm

    [...] Last week I visited the Flash Forum Conference in Cologne which was btw. great. A lot of inspiration and cool stuff. In his presentation Mario Klingemann talked about »Andre Michell’s Huge Bitmap hack«. The basic idea is to embed or load a large png and create a BitmapData by cloning it. The same approach can be found here. [...]

  8. Martin May 28, 2008 @ 2:53 pm

    try BitmapDataUnlimited available at http://blog.formatlos.de/2008/05/28/bitmapdataunlimited/

    I didn’t run into a limit using BitmapData.draw() method for huge BitmapDatas (8000px) so far

  9. Gradient Masking Gotcha « Summit Projects Flash Blog July 2, 2008 @ 9:22 pm

    [...] more related information here and it’s also good to note this forum discussion on Flash Player 10 changes to the [...]

  10. steven July 4, 2008 @ 12:22 pm

    HI there,

    This is great, I tried it with a bitmap size of 10000 px and it still works, but tried it with 13000 px and it failed, basically giving me an error saying it was a invalid bitmap.

    Any work around?

  11. [Workaround] Flash Bitmap maximum width and height August 25, 2008 @ 4:44 pm

    [...] . I was recently contacted by John Keyton who was really nice to point a work around created by Ronald Losbañes that would allow you to create a bitmapData object that is bigger than 2880 pixel in height and [...]

  12. Sean Powell December 6, 2008 @ 10:55 pm

    Using the loader object – that’s AS3 only right?

    No matter how you hijack larger bitmap data than the limit, you’re still not talking about an scalable solution for the common internet user’s computer – eating up upwards 800MB of RAM for a drawing app is not going to work for everyone.

    Seems more efficient to work out a process of using a smaller optimized version in flash, and a full size version on save/export. I’d love to see Adobe include classes / methods to support this approach.

    Also- it takes FOREVER to crunch bitmap data pixel for pixel and send to server for export, even if you are doing compression in flash. I have only seen one optimized method and even that can take over a minute for a large image…

  13. Ben January 8, 2009 @ 3:16 pm

    Hi!

    Do you have this solution in actionscript 2?

  14. Bong-Bong March 11, 2009 @ 11:42 pm

    AS2 is actually slower when it comes to binary data manipulation so it might not be a good idea. A client requested a version of this hack in ActionScript 2 once and we never came up with a workable solution. AS2 is just not that optimized to handle image manipulation that big.

  15. Flash animations April 13, 2009 @ 6:53 am

    We were developing a specialized application for a client. This application should be able to take an image template and allow users to customize (move/crop pictures, add message, etc.).

  16. one giant media January 8, 2010 @ 8:13 am

    Time to switch to AS3, if you haven’t already. ;) Much higher bitmap data limits in AS3.

  17. Vahakn March 11, 2010 @ 4:48 am

    Im being massive idiot. I really need to make some movies 3072 x 768. Ive downloaded the zip and made my dummy image, but what do i do with the open flash file and this action script? Ive hit play and ive hit publish and the size properties of the movie are still small

    Can anyone give me idiots instructions of how to get this workaround working for me?

    thanks so much

    Vahakn

  18. Bong-Bong March 14, 2010 @ 8:15 am

    Hi Vahakn, I’m surprised to see people still trying to use this hack. I guess Adobe Flash didn’t change their restriction on image size even if they support bigger images.

    Anyway first off make sure you’re purpose is not actually to make the flash movie of that size but to be able to have an image object inside flash that you could manipulate, draw, send to the server or whatever your end purpose is. If this is not the case then you’re looking for a different solution.

    Otherwise you need to make sure you’re using ActionScript 3. Next make sure the dummy image is of the correct size you want (3072×768) and flash could access it.

    This not magic script so pretty much you’ll have to tell it where to get the dummy image and what to do with that image object.

  19. Andrew June 17, 2010 @ 7:37 pm

    Indeed, nice trick.
    But blue on dark grey? yuck!

  20. ENRIQUE June 30, 2010 @ 3:51 pm


    PillSpot.org. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. No prescription pills. Buy drugs online

    Buy:Cialis Super Active+.Levitra.Viagra Professional.Viagra.Viagra Super Force.Maxaman.Cialis Professional.Viagra Super Active+.Viagra Soft Tabs.Super Active ED Pack.Soma.Zithromax.Tramadol.Cialis Soft Tabs.VPXL.Propecia.Cialis….

Leave a comment