Monday, June 23, 2008
BitmapData draw clipRect
Monday, June 23, 2008
I've found a situation using BitmapData that I'm sure many have run into. I have a sprite whose registration point is smack dab in the middle of it.
If I'd like to copy that Sprite and use it somewhere else too as a copy, I have to nest the Sprite in another Sprite so the registration point of the outer DisplayObject is 0, 0 and thus when I take a scrape of it using BitmapData, I don't just end up with the lower right quadrant of it.
I looked at the clipRect property of the draw method, and I tried negative x & y for it... which work GREAT for me here to avoid nesting... but it doesn't seem to work correctly at all.
var bmp:BitmapData = new BitmapData( 100, 100, true, 0xFFFFFF );
bmp.draw( someDispObj, null, null, "normal",
new Rectangle(-100,-100,200,200),true);
mySprite.addChild( bmp );
Hrmm. Well, for now it seems like I am shackled with nesting which is okay I guess. Just wish I didn't need to do that. Any solution in avoiding nesting to get something like this rolling?
Update:
Quasimondo (Mario Klingemann) posted a response to this posting here. I haven't tried the solution yet for scaling and rotation:
Update:
Quasimondo (Mario Klingemann) posted a response to this posting here. I haven't tried the solution yet for scaling and rotation:
function snapClip( clip:DisplayObject ):BitmapData
{
var bounds:Rectangle = clip.getBounds( clip.parent );
var bitmap:BitmapData = new BitmapData( int( bounds.width + 0.5 ),
int( bounds.height + 0.5 ), true, 0 );
bitmap.draw( clip.parent, new Matrix(1,0,0,1,-bounds.x,-bounds.y) );
return bitmap;
}
Comments:
There are currently 2 Comments:
-
Mario Klingemann said...“ClipRect is not your friend here, it's the matrix that you'll have to use: http://www.quasimondo.com/archives/000670.php”