/ Published in: ActionScript 3
Using lock() and unLock() saves about 20% when doing bulk pixel updates.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Create the bitmap var imgData:BitmapData = new BitmapData(500, 500, true, 0x00000000); var bmp:Bitmap = new Bitmap(imgData); // Invoke lock( ) imgData.lock( ); // Set pixel color-values var color:uint; for (var i:int = 0; i < imgData.height ; i++) { for (var j:int = 0; j < imgData.width; j++) { color = Math.floor(Math.random( )*0xFFFFFFFF); imgData.setPixel32(j, i, color); } } // Invoke unlock( ) imgData.lock( );