0

For the past few hours I have been trying to clone an image in Flex (using the Spark Components, but also trying to convert between Bitmap and BitmapImage).

What I am trying exactly is to create a simple painting application which keeps track of each Brush-Stroke. As soon as the Image on the Canvas has changed, it is to be cloned and then the clone is to be put into the History-Panel on the bottom of the application.

Things I have tried include:

  • Using ObjectUtils.clone(Object)
  • Creating BitmapData from Image.content, then making it a Bitmap and simply display it (Image doesn't have a content field, it says)
  • Performing a byte-copy and others I could find on the internet, of course.

So basically, how does one clone an Image (Spark Image) in Flex 4.6?

Thank you very much!

-- Danny Nophut

4

2 に答える 2

10

複製する代わりに、図面の画像を取得し、画像のビットマップをソースとして履歴画像に設定できます。次のようなことを行います

private function getBitmapData( target:DisplayObject ) : BitmapData
{

   //target.width and target.height can also be replaced with a fixed number.
   var bd : BitmapData = new BitmapData( target.width, target.height );
   bd.draw( target );
   return bd;
}

場合によっては、ターゲットの幅と高さが機能しない場合、getbounds メソッドを使用してオブジェクトの境界を取得し、境界から幅と高さを取得できます。

于 2012-03-12T16:40:28.110 に答える
1

ビットマップデータにはクローン機能があります:

public class EZB2ParkObject extends Image implements IEZB2ParkObject
{

    public function clone():IEZB2ParkObject{
        var n:IEZB2ParkObject   = new EZB2ParkObject();
        n.id = this.id;
        n.source = new Bitmap(BitmapData(this.source.bitmapData).clone());
        n.dimensions = this.dimensions;
        n.assetId = this.assetId;
        return n;
    }
}
于 2013-02-07T21:47:45.243 に答える