Posted By

allnatural on 03/19/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

TrentSkunk


BitmapData Set Each Pixel To Random Color


 / Published in: ActionScript 3
 

Using lock() and unLock() saves about 20% when doing bulk pixel updates.

  1. // Create the bitmap
  2. var imgData:BitmapData = new BitmapData(500, 500, true, 0x00000000);
  3. var bmp:Bitmap = new Bitmap(imgData);
  4. // Invoke lock( )
  5. imgData.lock( );
  6. // Set pixel color-values
  7. var color:uint;
  8. for (var i:int = 0; i < imgData.height ; i++) {
  9. for (var j:int = 0; j < imgData.width; j++) {
  10. color = Math.floor(Math.random( )*0xFFFFFFFF);
  11. imgData.setPixel32(j, i, color);
  12. }
  13. }
  14. // Invoke unlock( )
  15. imgData.lock( );

Report this snippet  

You need to login to post a comment.