ActionScript 3 带有Masked DisplayObject的AS3 bitmapData.draw()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 带有Masked DisplayObject的AS3 bitmapData.draw()相关的知识,希望对你有一定的参考价值。

// This code assumes there is a MovieClip on stage with the instance 
// name of 'pattern_mc'. Inside 'pattern_mc' there could be a mask which 
// is masking all the other layers.

var bounds:Rectangle = getRealBounds(pattern_mc);
var bmpd:BitmapData = new BitmapData(bounds.width, bounds.height);
var matrix:Matrix = new Matrix();
matrix.translate(-bounds.x, -bounds.y);
bmpd.draw(pattern_mc, matrix, null, null, null, true);
var bmp:Bitmap = new Bitmap(bmpd);

bmp.x = 20;
bmp.y = 20;
addChild(bmp);



function getRealBounds(displayObject:DisplayObject):Rectangle
{
	var bounds:Rectangle;
	var boundsDispO:Rectangle = displayObject.getBounds( displayObject );
	
	var bitmapData:BitmapData = new BitmapData( int( boundsDispO.width + 0.5 ), int( boundsDispO.height + 0.5 ), true, 0 );
	
	var matrix:Matrix = new Matrix();
	matrix.translate( -boundsDispO.x, -boundsDispO.y);
	
	bitmapData.draw( displayObject, matrix, new ColorTransform( 1, 1, 1, 1, 255, -255, -255, 255 ) );
	
	bounds = bitmapData.getColorBoundsRect( 0xFF000000, 0xFF000000 );
	bounds.x += boundsDispO.x;
	bounds.y += boundsDispO.y;
	
	bitmapData.dispose();
	return bounds;
}

以上是关于ActionScript 3 带有Masked DisplayObject的AS3 bitmapData.draw()的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 带有Zin init的基类模板

Actionscript 3 和带有 CDATA 的 XML

ActionScript 3 带有圆形预加载器微调器的AS3 Image Loader

ActionScript 3 AS3视频播放器,放置在时间轴上,带有旋转预加载器

如何在 Adob​​e Animate CC/ActionScript 3 中创建带有图片的滚动列表

使用带有actionscript 3 Flash cs6的矩形或线条创建2D重复模式