0
我嘗試捕獲渲染的SWF文件(圖表)的屏幕截圖,並使用以下代碼將其轉換爲圖像。但是,輸出圖像僅包含實際圖表的一部分。它沒有捕獲整個渲染的圖表......請幫助我......提前致謝。AS3 - ImageSnapshot - 不拍攝整個組件的快照
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
minWidth="955" minHeight="600"
backgroundColor="white" viewSourceURL="srcview/index.html" initialize="initApp()">
<mx:Script>
<![CDATA[
import mx.core.IUIComponent;
import mx.graphics.ImageSnapshot;
import mx.graphics.codec.PNGEncoder;
import flash.net.FileReference;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.controls.Alert;
private var image:ImageSnapshot = new ImageSnapshot;
private var dataXML:String="<chart labelDisplay='Normal' xAxisName='' yAxisName='' pyAxisName='' syAxisName='' rotateYAxisName='' caption='' subCaption='' baseFont='Regular' baseFontSize='10' baseFontColor='' decimalPrecision='' thousandSeparator=',' decimalSeparator='.' numberPrefix='' numberSuffix='' sNumberPrefix='' sNumberSuffix='' bgColor='' showBorder='1' YAxisMinValue='' YAxisMaxValue='' pyAxisMinValue='' pyAxisMaxValue='' syAxisMinValue='' syAxisMaxValue='' showLabels='1' showValues='1' showLegend='Y' legendPosition='Right'><categories><category label='Unmapped'/><category label='FY 2002 - 03'/><category label='FY 2003 - 04'/><category label='FY 2004 - 05'/><category label='FY 2005 - 06'/><category label='FY 2006 - 07'/><category label='FY 2007 - 08'/><category label='FY 2008 - 09'/><category label='FY 2009 - 10'/><category label='FY 2010 - 11'/></categories><dataset seriesName='Base Amount'><set value='-65770'/><set value='71461203'/><set value='66548822'/><set value='87063456'/><set value='261797187'/><set value='282962118'/><set value='3830823027'/><set value='16001588683'/><set value='22514728943'/><set value='23822586701'/></dataset></chart>";
private function initApp():void
{
chart_1.source="MSCombi2D.swf?chartWidth=100&chartHeight=100®isterWithJS=1&dataXML="+dataXML;
}
private function takeSnapshot(source:IBitmapDrawable):void {
// var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(source);
// var imageByteArray:ByteArray = imageSnap.data as ByteArray;
// var str:String = imageByteArray.
// swfLoader.load(imageByteArray);
var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(source);
swfLoader.source = new Bitmap(imageBitmapData);
// take a screen capture
// image = ImageSnapshot.captureImage(source, 72, new PNGEncoder(), false);
// var fileSave:FileReference = new FileReference();
// fileSave.save(image.data, "saveImage.png");
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button label="Take snapshot of DataGrid"
click="takeSnapshot(chart_1);" />
</mx:ApplicationControlBar>
<mx:HBox>
<mx:SWFLoader id="chart_1" />
<mx:SWFLoader id="swfLoader">
<mx:filters>
<mx:DropShadowFilter />
</mx:filters>
</mx:SWFLoader>
</mx:HBox>