Actionscript 3 如何在位图上绘制而不是在透明像素上绘制?
我需要在位图上绘制,但不需要在它的透明像素上绘制 示例图片如下: 我编写了以下代码:Actionscript 3 如何在位图上绘制而不是在透明像素上绘制?,actionscript-3,Actionscript 3,我需要在位图上绘制,但不需要在它的透明像素上绘制 示例图片如下: 我编写了以下代码: import flash.display.Bitmap; import flash.events.Event; import flash.geom.Matrix; var s:S = new S(); var m_bitmapData = new BitmapData(s.width, s.height, true, 0x00000000); m_bitmapData.draw(s); var hole=ne
import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Matrix;
var s:S = new S();
var m_bitmapData = new BitmapData(s.width, s.height, true, 0x00000000);
m_bitmapData.draw(s);
var hole=new Sprite();
var hole_matrix:Matrix
hole.graphics.beginFill(0x000000);
hole.graphics.drawCircle(0,0,30);
var bmp:Bitmap = new Bitmap(m_bitmapData);
bmp.x = 50
bmp.y =50
stage.addChild(bmp);
addEventListener(Event.ENTER_FRAME,asd);
function asd(e:Event):void{
hole_matrix=new Matrix();
hole_matrix.translate(mouseX-bmp.x,mouseY-bmp.y);
m_bitmapData.draw(hole,hole_matrix);
}
但结果是如图“否”
有人能解释一下吗?保留alpha频道,然后复制回来
var tempBD:BitmapData=new BitmapData(m_bitmapData.width,m_bitmapData.height,true,0);
...
function asd(e:Event):void {
...
tempBD.copyChannel(m_bitmapData,m_bitmapData.rect,new Point(),BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA);
m_bitmapData.draw(hole,hole_matrix);
m_bitmapData.copyChannel(tempBD,tempBD.rect,new Point(),BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA);
}
基本上是这样做的:在其他地方有一个与画布BitmapData大小相同的BitmapData,然后将alpha通道复制到该BitmapData中,绘制所需内容,然后将alpha通道复制回来。任何透明的东西都是透明的。注意,如果您永远不想更改alpha通道,您可以将其删除一次,然后恢复