FLEX对整个截屏或单个UI进行截图

虽然FLEX 3.0已经自带了截图的类,但是FLEX 2.0本身就可以简单的做出来截图功能,而且也是很简单的,下面粘出来给大家秀一下.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
 xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="absolute">
 <mx:Script>
  <![CDATA[
   import mx.core.UIComponent;
   private function captureFullScreen() : void     //截屏
   {
    var bd : BitmapData = getBitmapData( UIComponent( mx.core.Application.application ) );
    targetImage.source = new Bitmap( bd );
   }
   private function captureHiddenDatagrid() : void  //截单个UI
   {
    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;
   }
  ]]>
 </mx:Script>
 <mx:Button
  id="captureButton"
  label="Capture Full Screen"
  click="captureFullScreen()" />
 <mx:Button
  id="captureButton2"
  label="Capture Hidden Datagrid"
  click="captureHiddenDatagrid()" 
  x="153"/>
 <mx:Image
  id="targetImage"
  x="10"
  y="30"/>
 <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>
</mx:Application>

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: