AS3 Loop Through Pixels In A Bitmap


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.