How to save images in Flash CS3
Monday, March 31, 2008 Adobe Flash CS3 using the Bitmap is so improved that is immediately wanted to create a small Paint. We have already seen how to make a small Paint (see Paint in Flash CS3 Create a Painter: simple application for drawing in Flash CS3 Pro) that can support a true "gate" - erase function, thanks to a particular use of Layer Shape and Bitmap Let's say that Flash (as opposed to Flex) will not allow encoding (JPG or PNG) will auto-saving of bitmap images. However, you can overcome this obstacle by using a server-side scripting and the ability to send data in POST Flash.
Theory
The artifice that we can use is: read data in a bitmap pixel by pixel, convert them into hex values and send them to POST to a PHP page (in this example we use PHP and GD Library to actually create the ' image, but other solutions are equally effective).
Let's say that the only flaw of this technique is very slow, at least with Bitmap big enough (I tried with a Bitmap 640 x 300)!
Also, as you will see in ActionScript, you can check the progress of the deployment, but only get the event of the completion of all work; Actionscript + PHP.
PRACTICE
Given a bitmap, the algorithm can be used as follows:
- / **
- * @ Prototype: 0.0.1
- * @ Author: = undo =
- * @ Email: @ g.fazioli undolog.com
- * @ Web: http://www.undolog.com
- *
- * @ Params:
- *
- * __bitmap: Pointer to our bitmap
- * __width: Width in pixels
- * __height: Height in pixels
- *
- * /
- / / Copy reading - this could be avoided
- BitmapData = new BitmapData ( __width , __height ) ; var SBMP: BitmapData = new BitmapData (__width, __height);
- ( __bitmap ) ; SBMP. draw (__bitmap);
- / /
- ( sbmp . getPixel32 ( xx , yy ) . toString ( 16 ) ) ; pixels. push (SBMP. getPixel32 (xx, yy). toString (16));
- )
- )
- / /
- URLRequest = new URLRequest ( "http://miodominio.com/savebitmap.php" ) ; var urlReq: URLRequest = new URLRequest ( "http://miodominio.com/savebitmap.php");
- / /
- 'Completato' ) ; trace ( 'Completed');
- )
- )
- / /
- toString ( ) ; urlpar. pixels = pixels. toString ();
- = __height ; urlpar. __height height =;
- = __width ; urlpar. __width = width;
- = urlpar ; urlReq. urlpar = date;
- ( urlreq ) ; urlldr. load (urlReq);
How can we use PHP code:
- / **
- * @ Prototype: 0.0.1
- * @ Author: = undo =
- * @ Email: @ g.fazioli undolog.com
- * @ Web: http://www.undolog.com
- *
- * @ Params:
- *
- * __bitmap: Pointer to our bitmap
- * __width: Width in pixels
- * __height: Height in pixels
- *
- * /
- / / $ Pixels becomes an array with the values of individual pixels
- $_POST [ 'width' ] ; $ width = $ _POST [ 'width'];
- $_POST [ 'height' ] ; $ height = $ _POST [ 'height'];
- / / Create the image - @ avoid taking errors
- / / Write the pixels along the length and height
- 0 ; $ index = 0;
- $x = 0 ; $x <= $width ; $x ++ ) { for ($ x = 0; $ x <= $ width, $ x + +) (
- $y = 0 ; $y <= $height ; $y ++ ) { for ($ y = 0; $ y <= $ height, $ y + +) (
- imagecolorallocate ( $image , $r , $g , $b ) ; $ color = imagecolorallocate ($ image, $ r, $ g, $ b);
- $ index + +;
- )
- )
- / / Write image (JPG - but you can use a different format) on disk / server
We will return shortly on the subject by proposing other solutions ... ![]()
References and WEBGRAF:
- http://www.actionscripts.org/forums/showthread.php3?p=420106
- http://www.quasimondo.com/archives/000645.php
- Export a movie clip from Flash to an image file using C # / ASP.NET and ActionScript's BitmapData













Hi!
I would like make better my SQL capabilities.
I red really many SQL books and would like to
read more about SQL for my occupation as mysql database manager.
What would you recommend?
Thanks,
Werutz
Hi, i have some questions about you desing
maybe you can give designers contacts?
The above code is workiing perfectelly if we are exporting the SWF and height with less than 400 pixels. If we take the height and with more than 400 pixels then it's not working.
Can you please tell me, how can I save any more than 500x500 pixel bitmap from Flash?
@ Uday: Please check your PHP settings. Could be some timeout setting too low. To send bitmap pixel to the server in POST mode can take several minutes to process.