在Flex 4.6中克隆图像

Dan*_*hut 0 apache-flex clone image displayobject

在过去的几个小时里,我一直在尝试在Flex中克隆图像(使用Spark组件,但也尝试在Bitmap和BitmapImage之间进行转换).

我正在尝试的是创建一个简单的绘画应用程序,它跟踪每个Brush-Stroke.一旦"画布上的图像"发生变化,就会克隆它,然后将克隆放入应用程序底部的"历史记录"面板中.

我尝试过的事情包括:

  • 使用ObjectUtils.clone(Object)
  • 从Image.content创建BitmapData,然后将其设置为Bitmap并简单地显示它(图片没有内容字段,它说)
  • 当然,我可以在互联网上找到一个字节副本和其他副本.

基本上,如何在Flex 4.6中克隆Image(Spark Image)?

非常感谢你!

- Danny Nophut

Tri*_*ode 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;
}
Run Code Online (Sandbox Code Playgroud)

在某些情况下,如果目标的宽度和高度不起作用,您可以使用getbounds方法获取对象的边界,并从边界获取宽度和高度.