Home > Uncategorized > ImageSnapshot and BitmapData size limit

ImageSnapshot and BitmapData size limit

With Flex you can use ImageSnapshot class to copy FlexComponent to an image (PNG or JPEG).

It’s very easy, all you have to do if to execute those two lines :

var encoder:PNGEncoder= new PNGEncoder();
var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(mycomponent, 300, encoder);

mycomponent is you Flex component (UIComponent), 300 is the resolution (DPI) and I used a PNGEncoder to get a PNG file. I could have used a JPEGEncoder to get a Jpeg File.

This class uses BitmapData class to create a bitmap file and encode it. Until Flash Player 9, BitmapData was limited in size to 2880 pixels.
So if your component was bigger than that, it would be scalled to fit that size 2880 x 2880.

From Flash Player 10, BitmapData can go till 8191 pixels width or height. But it seems ImageSnapshot class was not updated. It still uses the old limit. So if you need more resolution on your screenshots, you will have to override the ImageSnapshot class.

I overrided it and set the const MAX_BITMAP_DIMENSION to 4600 and it’s working fine, and my screenshots are twice better.

UPDATE : 4600 was fine for a while, then depending on the area I try to create a snapshot from, it wasn’t always working.
I reduced it to 3950, and it’s working now.

Categories: Uncategorized
  1. Hoang Minh
    March 29, 2013 at 7:39 am

    how to set the const MAX_BITMAP_DIMENSION, please?

  2. weflex
    March 29, 2013 at 9:22 am

    I created a new class copy of the ImageSnapshot class.
    And then I set MAX_BITMAP_DIMENSION to a higer value.

    Actually it a good solution as long as your image isn’t bigger than the actual flash specifications : http://helpx.adobe.com/flash-player/kb/size-limits-swf-bitmap-files.html

    >FROM ADOBE :
    >
    >The largest square bitmap allowed is 4,095 x 4,095 pixels. Nonrectangular size limits vary, >for example, the following sizes all fit within Flash Player 10 limits:
    >
    >2169 x 7735
    >3133 x 5355
    >3315 x 5061
    >3615 x 4641
    >4095 x 4097
    >4097 x 4095
    >4641 x 3615
    >5061 x 3315
    >5355 x 3133
    >7735 x 2169

    If it’s bigger than that, you will need to find another solution. And the best one so far, is to lad an image with the size you need (a JPG, with a PNG it will crash). And then use its bitmap.
    Doing it that way allows you to manipulate a bitmap larger than what is specified by Adobe.
    I will post something about that soon.

  1. No trackbacks yet.

Leave a comment