I am stuck with this issue ..
I have a pie chart .now on button click i need to export it as a gif
image..
heard of using GIFencoder..can anyone throw light on this issue..
my code is as follows :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="vertical"
xmlns:components="components.*"
>
<components:PieChart id="pie1"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
//import flash.trace.Trace;
import mx.containers.VBox;
import flash.display.*;
import flash.events.*;
import flash.utils.ByteArray;
import mx.events.*;
import mx.utils.Base64Encoder;
import mx.rpc.events.ResultEvent;
[Bindable]
public var encodedstring:String;
private function eventHandlerr(): void{
Alert.show("hi1: " );
var bitdata:BitmapData = createBitmap(pie1);
Alert.show("bytes1: ");
var bytearray:ByteArray=ImgToByteArray(bitdata);
Alert.show("bytes3: " );
var lengthh:int=bytearray.length;
Alert.show("bytes: " +lengthh);
// encodeBytes(bytearray,0,lengthh);
//var encodedstring:String=encodeit(bytearray,lengthh);
encodedstring=encodeit(bytearray,lengthh);
Alert.show("string: ");
}
private function createBitmap(source:PieChart):BitmapData {
var bmd:BitmapData = new BitmapData(source.width,
source.height);
bmd.draw(source);
return bmd;
}
private function ImgToByteArray( bmpImg : BitmapData ) : ByteArray
{
var binaryImage : ByteArray = new ByteArray();
var bmpWidth:Number;
var bmpHeight:Number;
bmpWidth = bmpImg.width;
bmpHeight = bmpImg.height;
for( var i:uint=0; i< bmpWidth; i++ )
{
for( var j:uint=0; j<bmpHeight; j++ )
{
binaryImage.writeUnsignedInt( bmpImg.getPixel( i,
j ) );
}
}
return binaryImage;
}
/* public function encodeBytes(data:ByteArray,
offset:uint , length:int):void{
var benq:Base64Encoder = new Base64Encoder();
benq.encode("force",0,5);
var tmp:String = benq.toString();
return tmp;
} */
private function encodeit
(bytearray:ByteArray,lengthh:int): String {
var benq:Base64Encoder = new Base64Encoder();
benq.encodeBytes(bytearray,0,lengthh);
// benq.encode(bytearray,0,lengthh);
var tmp:String = benq.toString();
return tmp;
}
private function resultHandler(ev:ResultEvent):void{
}
]]>
</mx:Script>
<mx:Button id="btn1" label="Export Chart to gif" click="eventHandlerr
()" />
<mx:TextArea text="{encodedstring}"/>
</mx:Application>
right now am able to generate the byte array ..
But i have nio where done or added any header for GIF image...p
can anyone tell me what editing is reqd here...
Thx