The Fastest Way To Draw Pixels In ActionScript 3

ActionScript 3 can display a dynamically generated bitmap, in which the RGB values of each pixel are computed by code.It can be help us to render 3D scenes, process video and images, and create other effects.In order to draw a dynamically animated bitmap, it may be necessary to write to every pixel in the BitmapData each frame.We can call setPixel once for every pixel or build an appropriatedly sized ByteArray to do it.But which is the fastest?

The following is the fastest: Calls setPixels once per pixel, uses y in the outer loop and x in the inner loop, and locks and unlocks the BitmapData before and after writing to it. The main loop of code looks like this:

for(y = 0; y < STAGE_HEIGHT; ++y) { for(x = 0; x < STAGE_WIDTH; ++x) { r = (t*100 + 255 * x / STAGE_WIDTH)%255; g = 180; b = 180; outputBitmapData.setPixel(x, y, (r<<16) + (g<<8) + b); } } outputBitmapData.unlock();

1 thought on “The Fastest Way To Draw Pixels In ActionScript 3”

  1. I’ve played with a similar loop and found that the time to show the bitmap was up to 3 seconds, although I was testing from within the Flex Builder ….

    Were you able to write out a bitmap the size of the stage, let’s say 2000 x 2000, in a faster time with that?

    Kind Regards

Leave a Reply

Your email address will not be published. Required fields are marked *