46. *
47. * @returns 返回裁剪后的 BitmapData 对象。 48. */
49. public static function cutOutRect( target:DisplayObject, distanceX:N
umber, distanceY:Number, width:Number, height:Number, transparent:Boolean = true, fillColor:uint = 0x00000000 ):BitmapData 50. {
51. var m:Matrix = target.transform.matrix;
52. m.tx -= target.getBounds( target.parent ).x + distanceX; 53. m.ty -= target.getBounds( target.parent ).y + distanceY; 54.
55. var bmpData:BitmapData = new BitmapData( width, height, transpar
ent, fillColor );
56. bmpData.draw( target, m ); 57.
58. return bmpData; 59. } 60. 61. 62. 63. /**
64. * 超级裁剪工具!可裁剪任意形状!给定一个裁剪目标和一个模板,就可根据模板裁
剪出形状相配的 BitmapData 数据。 65. *
66. * @param target 需要裁剪的显示对象。 67. *
68. * @param template 裁剪模板,可以是任意形状。 69. *
70. * @returns 返回裁剪后的 BitmapData 对象。 71. */
72. public static function cutOutSuper( target:DisplayObject, template:D
isplayObject ):BitmapData 73. {
74. var rectTarget:Rectangle = target.transform.pixelBounds; 75. var rectTemplate:Rectangle = template.transform.pixelBounds; 76. var targetBitmapData:BitmapData = DisplayObjectTransformer.cutOu
tRect( target, 0, 0, rectTarget.width, rectTarget.height, true, 0x00000000 );
77. var templateBitmapData:BitmapData = DisplayObjectTransformer.cut
OutRect( template, 0, 0, rectTemplate.width, rectTemplate.height, true, 0x00000000 ); 78.
79. for( var pixelY:int = 0; pixelY < rectTemplate.height; pixelY++
)
80. {
81. for( var pixelX:int = 0; pixelX < rectTemplate.width; pixelX
++ )
82. {
83. if( templateBitmapData.getPixel( pixelX, pixelY ) != 0 )
84. {
85. var color:uint = targetBitmapData.getPixel32( pixelX
+ rectTemplate.x - rectTarget.x, pixelY + rectTemplate.y - rectTarget.y );
86. templateBitmapData.setPixel32( pixelX, pixelY, color
);
87. } 88. } 89. } 90.
91. return templateBitmapData; 92. 93. } 94. 95. 96. 97. } 98. }
分享到:
? 上一篇:SQL2005服务无法启动