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

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

问题描述

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

我正在尝试的是创建一个简单的绘画应用程序,跟踪每个画笔描边。只要Canvas上的图像发生了变化,就会被克隆,然后克隆将被放入应用程序底部的历史记录面板。



我已经尝试过的东西包括:

$ ul

  • 使用ObjectUtils.clone(Object)
  • 创建BitmapData Image.content,然后使其成为一个位图,只是显示它(图像没有内容字段,它说)

  • 执行字节复制
    和其他我可以当然也可以在网上找到。



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



    - Danny Nophut

    解决方案

    代替克隆,您可以获取图形的图像,并将图像的位图设置为历史图像的源代码,做一些像这样的事情。
    $ b pre $ private $ getBitmapData(target:DisplayObject):BitmapData
    {

    //target.width and target.height也可以用一个固定的数字来代替。
    var bd:BitmapData = new BitmapData(target.width,target.height);
    bd.draw(target);
    return bd;



    $ b $ p
    $ b

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


    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

    解决方案

    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;
    }
    

    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天全站免登陆