Memory management when pinching/zooming/panning large hi-res image in Adobe AIR iOS app

| | August 6, 2015

I’ve got a group of about 6 large hi-res images (roughly 7000×7000 each) and I’m trying to load them up into an Adobe AIR iPad app, and enable zoom and pan using TransformGestureEvent. In works fine in the debug player on my PC, but it’s crashing a lot when it gets to the device. I’ve tried a number of things to optimize it:

  • using the Greensock BlitMask (which helped, a little)
  • after loading, storing each object into a Vector so that if it was already loaded, I wouldn’t need to use another Loader.
  • reusing the Loader objects whenever possible and avoiding instantiation.

I’ve considered compressing the images and cutting their size in half, but I’d like to avoid that if possible.

Thanks.

(sorry for not posting code, it’s on my office computer)

One Response to “Memory management when pinching/zooming/panning large hi-res image in Adobe AIR iOS app”

  1. The reason it works fine on your computer is because your computer has more RAM than your phone. Your phone crashes when too much memory is being used on one application. To fix this, you can simply keep the image a small size by:

    [1] Make a box and convert it into a MovieClip and name it something like Box.

    [2] In your code, create a new shape (var shape:Shape = new Shape();)

    [3] In your library, export your bitmap for actionscript and name it something like ‘HighRes’.

    [4] Put this code in a GestureEvent (Box.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom)); where you create a new HighRes instance and fill it in the graphics of the shape as it gets larger or smaller when you zoom, such as:

    var reshigh = new HighRes(); 
    shape.graphics.width *= e.scaleX;
    shape.graphics.height *= e.scaleY;
    shape.graphics.beginBitmapFill((HighRes as Bitmap).bitmapData);
    shape.graphics.lineTo(Box.width * 3, 0);
    shape.graphics.lineTo(Box.width * 3, Box.height * 3);
    shape.graphics.lineTo(0, Box.height * 3);
    shape.graphics.lineTo(0, 0);
    shape.graphics.endFill();
    

    Please keep in note that this is untested code so you may need to make adjustments.

Leave a Reply