Hi, This will work as this worked for me;
http://sephiroth.it/tutorials/flashPHP/amfphp_bytearray/ you can create a bitmap data for a flex component using this code; /* flex code */ public function export_chart() { var ba:ByteArray = takeSnapshot(flex_chart); ba.compress(); //send this ba to server u can find more information about this from the link i have given above } private function takeSnapshot(component):ByteArray { var bitmapData:BitmapData = new BitmapData(component.width,component.height); bitmapData.draw(component); var jpegEncoder:JPEGEncoder = new JPEGEncoder(); var baScreenshot:ByteArray = jpegEncoder.encode(bitmapData); return baScreenshot; } On Oct 31, 4:42 pm, "subeesh a" <[EMAIL PROTECTED]> wrote: > Hi, > > I have not tried this, but i hope this will work . Since flex 3 cannot > write files to local file system directly, you have to pass the image > as ByteArray to server and use some server-side technology to create > the image file out of the ByteArray > > Any DisplayObject in Flex can be Converted to Bitmap using the > BitmapData class . Code would be something like this > > private function createBitmap(source:DisplayObject):BitmapData { > var bmd:BitmapData = new BitmapData(source.width, > source.height); > bmd.draw(source); > return bmd; > > } > > Once you get the BitmapData you need to convert that into ByteArray > .Code for that would be something like this > > 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; > } > > You can send this ByteArray to some server side technology like PHP to > create the image > > ( In Flex 4 we can directly access the local FileSystem and create > files. But a stable SDK is not released yet . If you want you can give > it a try with the nightly builds) > > Regards > Subeeshhttp://subeesh.wordpress.com/ > > On Fri, Oct 31, 2008 at 3:21 PM, Anil <[EMAIL PROTECTED]> wrote: > > > Hi, > > > Any solution to this problem... > > please respond.. > > > Thanks, > > Anil > > > On Oct 14, 7:39 pm, Anil <[EMAIL PROTECTED]> wrote: > >> Hi All, > > >> Here I'm pasting my sample code to export a Pie Chart. > > >> <?xml version="1.0"?> > >> <!-- Simple example to demonstrate the PieChart control. --> > >> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > >> xmlns:MyComps="mx.charts.*"> > > >> <mx:Script> > >> <![CDATA[ > > >> import mx.collections.ArrayCollection; > >> import mx.core.UIComponent; > >> import mx.graphics.codec.*; > >> import mx.printing.*; > >> import flash.events.*; > >> import flash.utils.Timer; > > >> [Bindable] > >> private var medalsAC:ArrayCollection = new ArrayCollection( [ > >> { Country: "USA", Gold: 35, Silver:39, Bronze: 29 }, > >> { Country: "China", Gold: 32, Silver:17, Bronze: 14 }, > >> { Country: "Russia", Gold: 27, Silver:27, Bronze: 38 } ]); > > >> var request:URLRequest; > > >> private function displayGold(data:Object, field:String, > >> index:Number, percentValue:Number):String { > >> var temp:String= (" " + percentValue).substr(0,6); > >> return data.Country + ": " + '\n' + "Total Gold: " + > >> data.Gold + '\n' + temp + "%"; > >> } > > >> private function export_itemClick(event:MouseEvent):void { > >> var ba:ByteArray = getByteArrayData(chart); > >> trace("PieChart in ByteArray: \n" + ba); > >> request = new URLRequest("save.php"); > >> request.method = URLRequestMethod.POST; > >> sendData(); > >> } > > >> private function sendData():void { > >> // code to handle the URL variable data to the server side and > >> helps in writing in to a file > >> } > > >> private function getByteArrayData( target:UIComponent ):ByteArray { > >> trace("Height: " + target.height + " Width: " + target.width); > >> var bd:BitmapData = new BitmapData(target.height, > >> target.width); > >> bd.draw(target, new Matrix()); > > >> var e:JPEGEncoder = new JPEGEncoder(); > >> return e.encode(bd); > >> } > > >> ]]> > >> </mx:Script> > > >> <mx:Panel id="panel1" title="Olympics 2004 Medals Tally Panel" > >> height="80%" width="70%"> > > >> <mx:PieChart id="chart" height="50%" width="50%" > >> paddingRight="5" paddingLeft="5" > >> showDataTips="true" dataProvider="{medalsAC}" > > > >> <mx:series> > >> <mx:PieSeries labelPosition="callout" field="Gold" > >> labelFunction="displayGold"> > >> <mx:calloutStroke> > >> <mx:Stroke weight="0" color="0x888888" > >> alpha="1.0"/> > >> </mx:calloutStroke> > >> <mx:radialStroke> > >> <mx:Stroke weight="0" color="#FFFFFF" > >> alpha="0.20"/> > >> </mx:radialStroke> > >> <mx:stroke> > >> <mx:Stroke color="0" alpha="0.20" weight="2"/> > >> </mx:stroke> > >> </mx:PieSeries> > >> </mx:series> > >> </mx:PieChart> > > >> <mx:Button id="export" label="Export PieChart as Image" > >> textAlign="center" > >> click="export_itemClick(event);"/> > > >> </mx:Panel> > > >> </mx:Application> > > >> Byte array conversion is not proper. I tried to trace the bytearray > >> printed in to the flashlog.txt. It looks like this "A¿A~A¿A" > > >> I tried it for many types of charts etc. But what ever bytearray it > >> wrote into the file is same. > >> What ever data it wrote in to the file is not fine and when I tried to > >> open the image ..its saying "Cant read file header" ..., "Unknown > >> fileformat". > > >> I am able to write some text in to file. Its working fine. but > >> exporting the image is not working. > > >> Can any one tell me where am I lost. > > >> Help me & guide me. > > >> Thanks, > >> Anil --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Flex India Community" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/flex_india?hl=en -~----------~----~----~----~------~----~------~--~---

