BitmapData.draw x Graphics.beginBitmapFill
Firstly… sorry for my poor English…
Working on Recyou.jp, I had to use many BitmapDatas, and so, I had to work out some way to make it lighter.
One thing I realized is that using Graphics.beginBitmapFill besides BitmapData.draw its much faster.
I made the benchmarks, drawing 10000 bitmapDatas, one using BitmapData.draw, and other using Graphics.beginBitmapFill.
First the benchmark with BitmapData.draw (Clicking on the flash it will re-run the benchmark):
The code is something like this:
var bmp:BitmapData = new BitmapData(100,100, false, 0×000000);
for(var i = 0; i < 10000; i++){
bmp.draw(genericBmp);
}
Now the benchmark with Graphics.beginBitmapFill (Clicking on the flash it will re-run the benchmark):
The code is something like this:
var bmp:BitmapData = new BitmapData(100,100, false, 0×000000);
for(var i = 0; i < 10000; i++){
graphics.beginBitmapFill(genericBmp);
graphics.drawRect(0,0,100,100);
}
So, if you are trying to create some bitmap pattens or attaching a Bitmap child and redrawing it’s BitmapData, try using the Graphics.beginBitmapFill.
dries said,
November 14, 2007 @ 8:16 pm
Ignore the idiot commenting on your english its a retard:P
Great work and great blog!
James said,
January 15, 2008 @ 7:40 am
Hey really cool stuff,
In my benchmarking though commands through the graphics class have a bigger impact on frame rate, for example drawing 10k bitmaps via beginBitmapFill may be accomplished in 23ms but you’re only going to take a much bigger hit to your framerate, than if you had only a single bitmap.
I can draw 4096 4×4 sprites to a bitmap and maintain 64fps. But doing the same thing via fill and clear drops to 22fps. Even though the later had a faster drawing routine.
I’m eager to see if further testing gets you the same result.
James
Jeroen said,
January 24, 2008 @ 3:44 am
If I try to use the bitmapdata.draw(video) function, I keep getting security errors since flashplayer 9,0,115,0.
Are you using the graphics.beginBitmapFill on the recyou.jp site?
Victor said,
April 3, 2008 @ 10:22 am
Nice!! You seem very familiar with the TextField class and it’s properties.
I was trying to copy my TextField to a BitmapData and I get a box around the text. Any idea how to work around this? I tried messing with the AntiAliasType, GridFitType, and other properties but nothing worked. I also tried placing the TF inside an MC with no success.
Here’s some code to consider. You can simply run this in the Flash IDE:
var t:TextField = new TextField();
t.text = “JOHN MAC”;
t.antiAliasType = flash.text.AntiAliasType.ADVANCED;
t.gridFitType = flash.text.GridFitType.SUBPIXEL;
t.autoSize = TextFieldAutoSize.LEFT;
t.background = false;
t.cacheAsBitmap = true;
t.textColor = 0×000000;
var mctf:MovieClip = new MovieClip();
var mctf02:MovieClip = new MovieClip();
mctf02.addChild(t);
var bitmapData:BitmapData = new BitmapData(t.width/1, t.height/1, false );
var bitmap:Bitmap = new Bitmap(bitmapData);
var scaleMatrix:Matrix = new Matrix();
scaleMatrix.scale(1, 1);
bitmapData.draw(mctf02, scaleMatrix);
mctf.addChild(bitmap);
addChild(mctf);
Any help/link is greatly appreciated
Victor said,
April 3, 2008 @ 10:38 am
Cool!! Just figured it out… Is always (maybe not) simpler than one might think…
change the line:
var bitmapData:BitmapData = new BitmapData(t.width/1, t.height/1, false );
To:
var bitmapData:BitmapData = new BitmapData(t.width/1, t.height/1, true, 0×00000000 );
0×000000 is just 0 alpha black. It could be any color…
Thanks…
Online and Downloadable financial Risk Server said,
June 10, 2008 @ 4:32 pm
Pull out…