在 Flex 4.6 中克隆图像 [英] Clone an Image in Flex 4.6

查看:21
本文介绍了在 Flex 4.6 中克隆图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我尝试过的事情包括:

  • 使用 ObjectUtils.clone(Object)
  • 从 Image.content 创建 BitmapData,然后将其设为 Bitmap 并简单地显示它(Image 没有内容字段,它说)
  • 执行字节复制当然还有其他我可以在互联网上找到的.

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

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

非常感谢!

-- 丹尼·诺普特

推荐答案

您可以获取绘图的图像并将图像的位图设置为历史图像的源,而不是克隆,请执行以下操作

Instead of cloning you can get the image of the drawing and set the bitmap of the image as source to the history image, do some thing like this

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 方法获取对象的边界,并从边界获取宽度和高度.

In some case if the width and height of the target is not working you can use the getbounds method to get the bounds of the object and from the bounds take the width and height.

这篇关于在 Flex 4.6 中克隆图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆