package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Rectangle; import flash.utils.ByteArray; [SWF(width=1200, height=600, backgroundColor=0x000000)] /** * Combines two images by drawing alternating rows from each image using getPixels()/setPixels(). */ public class graphic_flex_image_effects_03_Flex_SetPixelsTest extends graphic_flex_image_effects_03_Flex_DualImageTest { /** * Called after images load by super class. This uses getPixels()/setPixels() to draw alternating * rows of loaded bitmaps into new image. */ override protected function operateOnImages():void { var width:uint = _bitmapData0.width; var height:uint = _bitmapData0.height; var newData:BitmapData = new BitmapData(width, height); // the rectangle that will be used to draw a row var rect:Rectangle = new Rectangle(0, 0, width, 1); var bitmapData:BitmapData; var bytes:ByteArray; // runs through full height of loaded images for (var row:uint = 0; row < height; row++) { // alternates which image to draw the data from based on even/odd rows bitmapData = (row % 2) == 0 ? _bitmapData0 : _bitmapData1; rect.y = row; bytes = bitmapData.getPixels(rect); // necessary to set byte array back to 0 before reading in bytes.position = 0; newData.setPixels(rect, bytes); } // add the new bitmap var bitmap:Bitmap = new Bitmap(newData); addChild(bitmap); bitmap.x = _bitmap1.x + _bitmap1.width; } } }