0

画像のマスクされた領域のスナップショットを取得しようとしています...そのため、画像をロードして次の機能を実行します。

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 のマスクされた領域のスナップショットを取得したいのですが、どうすればよいかわかりません...何かアドバイスはありますか?

4

3 に答える 3

2

必要なものを達成するためのいくつかのアプローチがあります。最も簡単なのは、BitmapData を Matrix クラスで使用することです。

参照を除いて、保存方法は正しいようです。座標が正しくない可能性があります。_mask がコンテンツをマスクするシェイプであり、_bithold がマスクされたムービークリップであることを考慮すると、save メソッドは次のようになります。

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!

于 2009-12-14T17:34:09.397 に答える
1

BitmapData.copyPixels()を使用してみることができます。

于 2009-12-14T10:12:41.010 に答える
0

代わりにライブラリムービークリップを使用することにしました。ステージ上にあるMovieClip内に、必要なサイズのマスクされたムービークリップを使用してフレームを作成しました。

それで、ステージには「スナップ」という名前のムービークリップがあります。スナップの内側には、マスクとホルダーの2つのレイヤーがあり、どちらもムービークリップです。

ビットマップが読み込まれると、マスクレイヤーによって適切にマスクされたホルダームービークリップに追加します。次に、「スナップ」ムービークリップのスナップショットを撮ります。

プログラムで整理することもできたかもしれませんが、これははるかに高速で非常に簡単でした。

于 2009-12-14T11:19:03.440 に答える