【问题标题】:BitmapData of a masked image in ActionScript 3 (AS3)ActionScript 3 (AS3) 中蒙版图像的 BitmapData
【发布时间】:2009-12-14 02:02:23
【问题描述】:

我正在尝试拍摄图像的蒙版区域的快照...所以,我加载图像然后执行以下功能:

private function manageLoadedImage(e:Event):void
{

   _bitdata = e.currentTarget.content; // get the bitmap

   _bithold.addChild( _bitdata ); // add the bitmap to a sprite on the stage

   _bithold.x = holder1.x -((_bithold.width - holder1.width)/2); // center image

   _bithold.y = holder1.y -((_bithold.height - holder1.height)/2); // center image

   var m:Shape = new Shape(); // create the shape

   m.graphics.beginFill(0x0); // make the fill

   m.graphics.drawRect( this.x, this.y, holder1.width, holder1.height ); // draw the mask

   m.graphics.endFill(); // end the fill

   _bithold.mask = m; // mask the image


}// private function manageNewPaneAddition(e:Event):void

public function save( ):void
{

                          // WHAT DO I DO HERE ????????

   _bmdsrc = new BitmapData( holder1.width, holder1.height ); // create the new bitmapdata

    var m:Matrix = _bithold.transform.matrix; // lets try this out

    m.tx = -holder1.x + _bithold.width; // not sure what this means ?

    m.ty = -holder1.y + _bithold.height; // what does this mean ?

   _bmdsrc.draw( _bithold, m); // draw the bitmapdata

                        // END PROBLEM ??????????????

}// private function save(  ):void

所以,在我管理加载的图像之后,我保存它。但是保存功能只输出一个 80x80px 的白色方块。这告诉我,我正在对空白阶段进行快照。

MovieClip 构造如下:

我有一部电影,在该电影中我有一个缩略图编辑器名称 ThumbEdit。

ThumbEdit 在其舞台上有一个名为“holder1”的影片剪辑。在 ThumbEdit 的文档类中,我创建了一个精灵“_bithold”并将其放置在舞台上的 holder1.x 和 holder1.y 上。当图像加载时,我将图像添加到 _bithold 中,然后用形状屏蔽 _bithold。所以,我想获取 _bithold 的蒙面区域的快照,但我不确定我应该如何去做……有什么建议吗?

【问题讨论】:

    标签: flash actionscript-3 actionscript bitmap bitmapdata


    【解决方案1】:

    有一些方法可以实现您所需要的。最简单的方法是将 BitmapData 与 Matrix 类一起使用,就像您所做的那样。

    保存方法似乎是正确的,除了引用和坐标可能不正确。考虑到 _mask 是屏蔽内容的形状,而 _bithold 是被屏蔽的影片剪辑,您的保存方法应该如下所示:

    public function save( ):void
    {
    
       _bmp = new BitmapData( _mask.width, _mask.height ); // creates the bitmap of the mask's size
    
       var m:Matrix = new Matrix();
           m.translate( -_mask.x, -_mask.y ); // Create the matrix used to translate the positions of the source image.
    
       _bmp.draw( _bithold, m); // draw the bitmapdata considering the offset of the mask
    
    
       addChild( new Bitmap(_bmp) ); // just attaching the result on the screen, to see the result.
    
    }
    

    需要注意的是,转换矩阵对象的行必须输入相对于 _bithold 影片剪辑的值。这意味着如果遮罩形状和遮罩对象(_bithold)不在同一个父级中,则需要使用 globalToLocal 和 localToGlobal 方法将坐标带到影片剪辑父级。

    还有什么疑问,我来了!

    干杯, CaioToOn!

    【讨论】:

    • 酷!谢谢您的帮助。我现在实现了一个简单的时间线解决方案,但会在不久的将来尝试你的。然后会在这里发回。
    • 非常感谢!一直在网上搜寻解决此问题的好方法,并且效果很好。太棒了!
    【解决方案2】:

    您可以尝试使用 BitmapData.copyPixels()。

    【讨论】:

      【解决方案3】:

      我决定改用库影片剪辑。我在舞台上的 MovieClip 内创建了一个带有蒙版动画剪辑的帧。

      所以,在舞台上,我有一个名为“Snap”的影片剪辑。内部 snap 是两层,mask 和 holder,都是 Movieclips。

      当位图加载时,我将它添加到被遮罩层适当遮罩的持有者影片剪辑中。然后,我拍摄“Snap”电影剪辑的快照。

      我可能可以通过编程方式对其进行排序,但这要快得多且非常简单。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多