-1

SWFthrogugh AS3 から PNG 画像を生成しようとしましたが、機能しません...何が問題だったのか教えてください...

    package {
    import com.adobe.images.PNGEncoder; 
    import flash.display.BitmapData;    
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IEventDispatcher;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import flash.net.URLLoader;
    import flash.net.URLVariables;
    import com.dynamicflash.util.Base64;
    import flash.net.URLRequestMethod;
    import flash.net.URLLoaderDataFormat;
    import flash.net.navigateToURL;
    import flash.net.FileReference;
    import flash.system.ApplicationDomain;
    import flash.system.LoaderContext;  

    public class SampleCircle extends Sprite
    {
        public var loader:Loader;
        public var loaderA:Loader;
        public var ba: ByteArray;
        public function SampleCircle()
        {
            drawSWF();           
        }
        public function drawSWF():void
        {

            var request:URLRequest = new URLRequest("E:/Workbook/swftoimage_visual_c_sharp/bin/Debug/dw_mxml_ar_kaplab_treemap_chartAAA.swf"); 
            loader = new Loader(); 
            loader.load(request); 
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
            addChild(loader);
        }
        public function onComplete(e:Event):void
        {

            var b: BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false,0xDEDEDE);  
            b.draw(loader);             
            ba = PNGEncoder.encode(b);
            loader.loadBytes(ba);           
            addChild(loader);               
        }       
    }
}
4

2 に答える 2

0

同じローダーをインラインで使用しています

        b.draw(loader);             
        ba = PNGEncoder.encode(b);
        loader.loadBytes(ba);         // In above function you have used same loader  
        addChild(loader);     

新品で試せると思います。

于 2012-08-14T11:13:00.563 に答える
0

次のコードでなんとか画像を取得できました(コードにはまだ問題があります)...ありがとう

<?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>

于 2012-08-15T10:43:15.817 に答える