I am working on an app for the iPad 3 (but this is not an iOS specific problem so I'm posting it here) which includes a fullscreen gallery in one area. The gallery mimics the iPad's native photo gallery in function; the user can swipe left and right between images.
I had noticed that running on the device, the app would freeze for a moment as it reached the edge of each photo - a small amount of lag as it loaded the next 2048*1536 photo into the display. I figured I could solve this by cutting the photos into smaller pieces with code, and that works:
for (var j:int = 0; j < parts; j++) {
bmpD = new BitmapData(bmpWidth/parts, bmpHeight, false, 0x333333);
rect = new Rectangle((bmpWidth / parts)*j, 0, bmpWidth / parts, bmpHeight);
bmpD.copyPixels(bmp, rect, point);
bitmap = new Bitmap(bmpD);
bitmap.x = (bmpWidth / parts) * j;
bitmap.y = (stageHeight - bmpHeight) / 2;
mc.addChild(bitmap);
}
However, running this loop when the gallery opens causes a ~5 second delay in the loading of the gallery (made up of 8 images), vs less than a second without the loop. It causes a ~1 second delay on my PC, vs no delay without the loop. This happens regardless of how many loop iterations occur. There is no noticable difference in load time between parts = 2 and parts = 128.
I had gotten the impression copyPixels is pretty fast, but this loop takes a horrendously long time to execute. It also doesn't make sense to me that the length of time required to execute the loop wouldn't be affected by the number of iterations. Am I missing something? Or is the problem just the volume of pixels that have to be copied, regardless of how many are copied at once?