如何从FLEX应用程序中取出“打印屏幕”并将其保存到硬盘?

时间:2010-04-12 14:32:54

标签: flex flash actionscript-3 mxml printscreen

所以我的应用程序有这样的代码

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Script>
        <![CDATA[
            protected function prtscrn_clickHandler(event:MouseEvent):void
            {
                // save current RIA view as a PNG or JPG to users FileSistem
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button x="21" y="10" label="Print Screen" id="prtscrn" click="prtscrn_clickHandler(event)"/>
    <s:TitleWindow x="45" y="98" width="282" height="303">
        <s:CheckBox x="25" y="10" label="CheckBox"/>
        <s:Button x="24" y="44" label="Button"/>
        <mx:DateChooser x="24" y="76"/>
    </s:TitleWindow>
</s:Application>

我想在点击按钮时将“打印屏幕”等内容保存到用户硬盘上。

如何做这样的事情?

1 个答案:

答案 0 :(得分:2)

不幸的是,你无法在整个用户的桌面上打印屏幕,你只能在“打印屏幕”中找到flash文件。下面的伪代码:

var b:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
b.draw(stage);

// create reference that will be the saved file
var ref:FileReference = new FileReference();

// add listeners for filereference ...

// save the bitmapdata
ref.save(b.getPixels(b.rect));