flex 4中 实现在线截图
一下是截图代码
<?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:Declarations><!-- 将非可视元素(例如服务、值对象)放在此处 --></fx:Declarations><fx:Script><![CDATA[import mx.core.UIComponent;import mx.graphics.ImageSnapshot;import mx.graphics.codec.JPEGEncoder;/** * 截取全屏幕 * */private function captureFullScreen() : void{var bd : BitmapData = getBitmapData( UIComponent( mx.core.Application.application ) );targetImage.source = new Bitmap( bd );}/** * 截取单个UI * */private function captureSingleScreen() : void {var bd : BitmapData = getBitmapData( UIComponent( hiddenDg ) );targetImage.source = new Bitmap( bd );}/** * 截图功能函数 * */private function getBitmapData( target : UIComponent ) : BitmapData {var bd : BitmapData = new BitmapData( target.width, target.height );var m : Matrix = new Matrix();bd.draw( target, m );return bd;}/** * 截取并保存 * */private var jpgeEnc:JPEGEncoder=new JPEGEncoder();private var fileReference:FileReference=new FileReference();private function captureImage():void{var imgSnapshot:ImageSnapshot=ImageSnapshot.captureImage(UIComponent( mx.core.Application.application ),0,jpgeEnc);fileReference.save(imgSnapshot.data,"未命名.jpg");}]]></fx:Script><mx:Button id="capturefullSave" label="Capture Screen Save" click="captureImage()" x="169" y="5"/><mx:Button id="capturefull" label="Capture Full Screen" click="captureFullScreen()" x="10" y="4"/><mx:Button id="capturesingle" label="Capture Hidden Datagrid" click="captureSingleScreen()" x="322" y="5"/><mx:Image id="targetImage" x="10" y="30"/><!--截取单个DataGrid--><mx:DataGrid x="99" y="64" id="hiddenDg" visible="false"><mx:columns><mx:DataGridColumn headerText="Column 1" dataField="col1"/><mx:DataGridColumn headerText="Column 2" dataField="col2"/><mx:DataGridColumn headerText="Column 3" dataField="col3"/></mx:columns></mx:DataGrid></s:Application>