Posted By

adrianparr on 06/02/11


Tagged

loop itteration getpixel while bitmapData as3 bitmap setPixel pixels


Versions (?)

AS3 Loop Through Pixels In A Bitmap


 / Published in: ActionScript 3
 

URL: http://spilled-milk.com/blog/2010/06/30/faster-pixel-loop-itteration/

  1. import flash.display.Bitmap;
  2. import flash.display.BitmapData;
  3.  
  4. var bmpd:BitmapData = new LibraryBitmap(1,1);
  5. var bitmap:Bitmap = new Bitmap();
  6. bitmap.bitmapData = bmpd;
  7. addChild(bitmap);
  8.  
  9. var wide:int = bmpd.width;
  10. var tall:int = bmpd.height;
  11. var totalPixels:int = wide * tall;
  12. trace("wide: " + wide);
  13. trace("tall: " + tall);
  14. trace("totalPixels: " + totalPixels);
  15. var index:int = totalPixels + 1;
  16. var useIndex:int;
  17. var xPixel:int;
  18. var yPixel:int;
  19. while (--index > 0) {
  20. useIndex = index - 1;
  21. xPixel = useIndex % wide;
  22. yPixel = int(useIndex / wide);
  23. bmpd.setPixel(xPixel, yPixel, 0xff0000);
  24. }

Report this snippet  

You need to login to post a comment.