开发者

whats the most efficient way to overwrite bitmapdata

I have a bitmapdata object that is filled with n rectangles of a width of 1 pixel and of varying heights.

I want to run through a loop and remove the old rectangle and replace it with a different one.

Should I 开发者_JS百科do something like reset the each bitmap column of pixels to a background color and then add the rect i want?

for(i:int=0;i<bitmapdata.width;++i)

{
   (for var j:int=0;j<bitmapdata.height;j++)
{
  bitmapdata.setPixel(i,j,0x000000)
}

bitmapdata.fillrect(my new rect,0xffffff)


}


Well, I notice that you're using fillRect for something, why not use it for everything? Just fillRect the column in question, and then do another fillRect from the bottom up to make the new rectangle.

I'm not sure if that's the fastest way to do it, but you could try copyPixels, which I've heard is very fast. My suggestion for using this without any pain whatsoever is to assemble a bitmap that goes from having a column with 0px height to full height, and when you need a column of X height, copy from the pre-made bitmap at column X, and copy it to column Y on the original "bunch of bars" image.

Hope it helps. Post comments and I'll try to clarify in the answer, if need be.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜