Hi,

Here is my way to export image (PNG or JPEG) to a PHP server. The image is available as if you post it on a HTML form, so in $_FILES variables.

First, I've added this 2 methods in JPEG and PNG encoder class :

       public function encodeFromUI(target:UIComponent):ByteArray {
return this.encode(getUIComponentBitmapData(target)); } private function getUIComponentBitmapData( target : UIComponent ) : BitmapData { var bd : BitmapData = new BitmapData( target.width, target.height );
           var m : Matrix = new Matrix();
           bd.draw( target , m );
return bd; }

I've created a new method that encode and send the image :

   var png:PNGEnc = new PNGEnc();   // PNGEnc is faster than JPEG encoder
   var imageData:ByteArray = png.encodeFromUI(UIComp);
var url:URLRequest = new URLRequest('http://your_url/print_bitmap.php'); var boundary:String = '------MIKA------';
   url.contentType = 'multipart/form-data; boundary='+boundary;
   boundary = '--'+boundary;
var data:ByteArray = new ByteArray; data.writeUTFBytes(boundary+'\r\n');

   // start new part
data.writeUTFBytes('Content-Disposition: form-data; name="file_upload"; filename="image.png"\r\n');
   data.writeUTFBytes('Content-Type: image/png\r\n');
   data.writeUTFBytes('Content-Transfer-Encoding: binary\r\n\r\n');
   // write image data
   data.writeBytes(imageData);
   // terminate part
   data.writeUTFBytes('\r\n'+boundary+'\r\n');
// start a new part if you want to send other POST variables data.writeUTFBytes('Content-Disposition: form-data; name="test"\r\n\r\n');
   data.writeUTFBytes('mikaflash');
   data.writeUTFBytes('\r\n'+boundary+'\r\n');

   url.data = data;
   url.method = URLRequestMethod.POST;
/*var Loader:URLLoader = new URLLoader();
   Loader.addEventListener(Event.COMPLETE,onLoadComplete);
   Loader.load(url);
   */
navigateToURL(url,'_self'); Hope this helps you. May be there is a better way to do this, but it's working fine for me.

Mickael



Paramjit Jolly a écrit :

Hi Prateek,

 I have seen your query, I am also looking for similar solution.

Infact similar stuff I come across 3 years back When I was working with flash-java.

That time I used POI for exporting charts & grid data in excel sheets which are templates (place holders) in server.

Now our client wants similar look & feel charts as  Flex.

For report generation I have tested

Adobe life cycle is perfect product, I m trying for images of charts also.

Bty why u need image, if only for printing you can print using print job class.

Also check for flash paper.

Let me know if you get something goot for this.

Regards

Jolly

************************************************************************
**Life Fitness** - A Division of Brunswick Corporation
Singapore-486066
http://www.lifefitness.com <http://www.lifefitness.com> | http://www.brunswick.com <http://www.brunswick.com>
************************************************************************

------------------------------------------------------------------------

*From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *., Prateek (MSAS Sys Dev IBD)
*Sent:* Wednesday, February 14, 2007 8:16 PM
*To:* flexcoders@yahoogroups.com
*Subject:* [flexcoders] Exporting Charts as Image

Hi All

We are using Flex charts in our web app. We also have a need to export the chart as an image so that the same can be embedded in an email sent out to users.

Any pointers ?

Thanks

Prateek

------------------------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.

Reply via email to