Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3-ImageSnapshot-不拍摄整个组件的快照_Actionscript 3 - Fatal编程技术网

Actionscript 3 AS3-ImageSnapshot-不拍摄整个组件的快照

Actionscript 3 AS3-ImageSnapshot-不拍摄整个组件的快照,actionscript-3,Actionscript 3,我尝试捕获渲染SWF文件(图表)的屏幕截图,并使用以下代码将其转换为图像。但是,输出图像仅包含渲染的实际图表的一部分。它不是捕获整个渲染图表…请帮助我…提前感谢 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" ba

我尝试捕获渲染SWF文件(图表)的屏幕截图,并使用以下代码将其转换为图像。但是,输出图像仅包含渲染的实际图表的一部分。它不是捕获整个渲染图表…请帮助我…提前感谢

<?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&registerWithJS=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>


我得到了答案……我将函数“takeSnapshot”的代码更改如下:

   private function takeSnapshot(source:IBitmapDrawable):void 
        {                          
            var bitmapData:BitmapData = new BitmapData( 1350, 700 );
            bitmapData.draw( IBitmapDrawable( chart_1 ));
            var swfBitmap:Bitmap = new Bitmap( bitmapData );            
            var jpg:JPEGEncoder = new JPEGEncoder(100); 
            var ba:ByteArray  = jpg.encode(swfBitmap.bitmapData); 
            var fileSave:FileReference = new FileReference();
            fileSave.save(ba, "saveImage.jpg");
        }