flex 3 中的 DisplayObject 快照 [英] DisplayObject snapshot in flex 3

查看:28
本文介绍了flex 3 中的 DisplayObject 快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 flex 中创建一个可视化编辑器,需要让用户将他们的项目导出为图像格式.但我有一个问题:画布的大小是固定的,当用户添加超出这些大小的元素时,会添加一些滚动条.并且用户继续在该项目上工作.但是当他想拍摄画布的快照时,他只需使用滚动条获取画布的可见部分.如何获取全尺寸画布的图像?

i'm creating a visual editor in flex and need to let users export thier projects into Image format. But i have one problem: size of the canvas is fixed and when user add element which is out of these sizes some scroll bars added. And user continue working on the project. but when he want to take snapshot of the canvas he just get the visible part ot the canvas with scrollbars. how to get image of the fullsize canvas?

我找到的唯一解决方案是检查画布子对象的位置和大小,并对其进行调整以适应它们.然后拍摄并调整大小.但它嗯......我觉得太复杂了.有没有一些简单的方法"?

The only solution i found is to check the positions and sizes of canvas child objects and rezise it to fit them. then take snap and resize back. But it hmmmm... too complicated i think. Is there some "easy methods"?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
    <![CDATA[
        import mx.graphics.ImageSnapshot;

        private function SnapshotButtonHandler():void
        {
            var snapshot:ImageSnapshot = ImageSnapshot.captureImage(AppCanvas);
            var file:FileReference = new FileReference();
            file.save(snapshot.data, "canvas.png");
        }
    ]]>
</mx:Script>
<mx:Canvas id="AppCanvas" width="800" height="300" backgroundColor="0xFFFFFF">
    <mx:Box x="750" y="100" width="100" height="100" backgroundColor="0xCCCCCC" />
</mx:Canvas>
<mx:Button id="SnapshotButton" label="take snapshot" click="SnapshotButtonHandler()" /> 
</mx:Application>

推荐答案

krishna:确保在构建路径中针对 Flash Player 10.

krishna: make sure you're targeting flash player 10 in your build path.

这篇关于flex 3 中的 DisplayObject 快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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