簡體   English   中英

Flex 3中的DisplayObject快照

[英]DisplayObject snapshot in flex 3

我正在Flex中創建一個可視化編輯器,需要讓用戶將其項目導出為Image格式。 但是我有一個問題:畫布的大小是固定的,並且當用戶添加超出這些大小的元素時,會添加一些滾動條。 並且用戶繼續進行該項目。 但是,當他想為畫布拍攝快照時,他只是使用滾動條來獲取畫布的可見部分。 如何獲取全尺寸畫布的圖像?

我發現的唯一解決方案是檢查畫布子對象的位置和大小,並調整其大小以適合它們。 然后快速調整尺寸。 但是,嗯...我覺得太復雜了。 是否有一些“簡便方法”?

<?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>

我將一個容器放到可滾動的畫布中,該容器根據其中的對象調整其大小...也許甚至UIComponent也可以解決問題...然后對該容器進行快照...畫布僅添加滾動條,因此說話 ...

格里茨

back2dos

我找到的解決方案

BaseCanvas-具有固定高度和寬度的畫布EditCanvas-參數取決於其子位置的動態畫布。

快照來自EditCanvas。 這部分代碼

private function SnapshotButtonHandler():void
{
    var snapshot:ImageSnapshot = ImageSnapshot.captureImage(EditCanvas);
    var file:FileReference = new FileReference();
    file.save(snapshot.data, "canvas.png");
}
private function ResizeCanvas():void
{
    for each (var child:* in AppCanvas.getChildren())
    {
        if ((child.x + child.width) > AppCanvas.width)
            AppCanvas.width = child.x+child.width;
        if ((child.y + child.height) > AppCanvas.height)
            AppCanvas.height = child.y+child.height;
    }
}

<mx:Canvas id="BaseCanvas" width="300" height="200">
    <mx:Canvas id="EditCanvas" width="300" height="200" backgroundColor="0xFFFFF0" horizontalScrollPolicy="off" verticalScrollPolicy="off"/>
</mx:Canvas>

克里希納:確保在構建路徑中定位Flash Player 10。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM