Skip to main content
March 30, 2012
Answered

BitmapData method lock not work.

  • March 30, 2012
  • 1 reply
  • 769 views

import flash.display.BitmapData;

import flash.display.Bitmap;

import flash.geom.Rectangle;

var bmd:BitmapData = new BitmapData(100, 100, false, 0xFF0000);

var bitmap:Bitmap = new Bitmap(bmd);

addChild(bitmap);

bmd.lock();

for (var i:uint = 0; i < 50; i++)

{

          for (var j:uint = 0; j < 50; j++)

          {

                         bmd.setPixel(i + 25, j + 25, Math.random() * 0xFFFFFF);

          }

}

I don't wont see random colors in center of red rect, but i see it. What i do wrong?

This topic has been closed for replies.
Correct answer _spoboyle

mr.shumi wrote:

i haven't worked with bitmap before

but you are telling him to show random colors here

Math.random() * 0xFFFFFF

yes

bmd.setPixel(i + 25, j + 25, Math.random() * 0xFFFFFF);

randomly sets pixels in his bitmapdata

however the previous call to

bmd.lock()

means the contents on bitmapdata should change but the bitmap object should not be updated until bmd.unlock() is called (which in this example it is not)

lucky: I'm looking into it, and unhelpfully it should work, and I can't see why it wouldn't be I'll try and get back to you

1 reply

March 30, 2012

i haven't worked with bitmap before

but you are telling him to show random colors here

Math.random() * 0xFFFFFF

_spoboyle
_spoboyleCorrect answer
Inspiring
March 30, 2012

mr.shumi wrote:

i haven't worked with bitmap before

but you are telling him to show random colors here

Math.random() * 0xFFFFFF

yes

bmd.setPixel(i + 25, j + 25, Math.random() * 0xFFFFFF);

randomly sets pixels in his bitmapdata

however the previous call to

bmd.lock()

means the contents on bitmapdata should change but the bitmap object should not be updated until bmd.unlock() is called (which in this example it is not)

lucky: I'm looking into it, and unhelpfully it should work, and I can't see why it wouldn't be I'll try and get back to you

_spoboyle
Inspiring
March 30, 2012

firstly the lock is working, in terms of increasing performance, removing the lock() increases the amount of time require to execute the code

although I cannot confirm it at the moment my suspicion is that when the display list comes to render itself it automatically updates all bitmap objects with their associated bitmapdatas.