Flex保存画布和删除图像

时间:2021-02-03 21:23:26

I have an image loaded from an url and added to canvas as child. Then I am drag and dropping another image on it which also uses the senocular transform so the image can be transformed on the canvas. I have coded in such way that the transform handles shows up only after it's dropped on canvas. The image shows up correctly. But I am trying to save the result image (that is the main image and the dropped image on top of it), I only end up with the main image that was loaded earlier. The dropped image doesn't show up.

我有一个从网址加载的图片,并作为孩子添加到画布。然后我拖放另一个图像,它也使用了senocular变换,因此可以在画布上转换图像。我编码的方式是变换句柄只有在画布上删除后才显示出来。图像正确显示。但我试图保存结果图像(即主图像和它上面的删除图像),我最终只得到了之前加载的主图像。丢失的图像不会显示。

Below is the code for handleDrop() that is fired on dragDrop event and prepares the final image. What am I doing wrong?

下面是在dragDrop事件上触发的handleDrop()代码,并准备最终图像。我究竟做错了什么?

var dragInitiator:IUIComponent = dragEvent.dragInitiator;
                var dropTarget:IUIComponent = dragEvent.currentTarget as IUIComponent;

                var tool:TransformTool = new TransformTool(new ControlSetStandard());
                var items:String = dragEvent.dragSource.dataForFormat("items") as String;

                var img:Image = new Image();

                img.x=50;
                img.y=50;
                img.width=55;
                img.height=55;

                img.source=items.toString();
                var bitmap:Bitmap= Bitmap(img.content);


                var tool:TransformTool = new TransformTool(new ControlSetStandard());   
                var component:UIComponent = new UIComponent( );
                tool.target = img;

                tool.x=myCanvas.x;
                tool.y=myCanvas.y;



                addElement(component);

                myCanvas.addChild(img);
                img.z=myCanvas.z+1;
                component.addChild(tool);
                original=new BitmapData(bmd.width,bmd.height,true,0x000000FF);
                original.draw(myCanvas);

1 个解决方案

#1


1  

Just because you added the image to the canvas doesn't mean it has drawn already. Either listen for the updateComplete event on the image or do a callLater to a function that then draws the bitmap.

仅仅因为你将图像添加到画布并不意味着它已经绘制了。要么监听图像上的updateComplete事件,要么对一个函数执行callLater,然后绘制位图。

#1


1  

Just because you added the image to the canvas doesn't mean it has drawn already. Either listen for the updateComplete event on the image or do a callLater to a function that then draws the bitmap.

仅仅因为你将图像添加到画布并不意味着它已经绘制了。要么监听图像上的updateComplete事件,要么对一个函数执行callLater,然后绘制位图。