With the use of Adobe Flash CS3 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 ) can support a true "eraser" - erase function, thanks to a particular use of Layer Shape and Bitmap . Let's say that Flash (as opposed to Flex) it does not allow encoding (such as JPG or PNG) it automatically saves the Bitmap images. However you can get around it using a server-side scripting and the ability to send data in POST Flash.
The theory
The artifice that we can use is as follows: read the data in a bitmap pixel by pixel, they turn into hexadecimal values and send them to POST to a PHP page (in this example we use PHP and the GD Library to create the actual ' image, but other solutions are equally effective).
Let's say that the only drawback 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 the Actionscript code, you can check the progress of the deployment, but only get the event the completion of all work; Actionscript + PHP.
THE PRACTICE
Given a bitmap to use the algorithm can be the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | / ** * @ 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 to read - this could be avoided BitmapData = new BitmapData ( __width , __height ) ; var sbmp: BitmapData = new BitmapData (__width, __height); ( __bitmap ) ; sbmp. draw (__bitmap); / / Array = new Array ( ) ; var pixels: Array = new Array (); var xx : uint = 0 ; xx < = __width ; xx ++ ) { for (var xx: uint = 0; xx <= __width; xx + +) { var yy : uint = 0 ; yy < = __height ; yy ++ ) { for (var yy: uint = 0; yy <= __height; yy + +) { ( 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"); URLVariables = new URLVariables ( ) ; var urlpar: URLVariables = new URLVariables (); URLLoader = new URLLoader ( ) ; var urlldr: URLLoader = new URLLoader (); / / ( Event . COMPLETE , urlldr. addEventListener ( Event . COMPLETE e : Event ) : void { function (e: Event ): void { 'Completato' ) ; trace ('Completed'); } ); / / toString ( ) ; urlpar. pixels = pixels. toString (); = __height ; urlpar. __height = height; = __width ; urlpar. __width = width; = urlpar ; urlreq. urlpar = date; = URLRequestMethod . POST ; urlreq. method = URLRequestMethod . POST; ( urlreq ) ; urlldr. load (urlreq); |
How we can use PHP code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | / ** * @ 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 explode ( "," , $_POST [ 'pixels' ] ) ; $ Pixels = explode ("", $ _POST ['pixels']); $_POST [ 'width' ] ; $ Width = $ _POST ['width']; $_POST [ 'height' ] ; $ Height = $ _POST ['height']; / / Create the image - @ issue avoiding errors imagecreatetruecolor ( $width , $height ) ; $ Image = @ imagecreatetruecolor ($ width, $ height); / / 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 + +) { hexdec ( "0x" . substr ( $pixels [ $index ] , 2 , 2 ) ) ; $ R = hexdec ("0x." substr ($ pixels [$ index], 2, 2)); hexdec ( "0x" . substr ( $pixels [ $index ] , 4 , 2 ) ) ; $ G = hexdec ("0x." substr ($ pixels [$ index], 4, 2)); hexdec ( "0x" . substr ( $pixels [ $index ] , 6 , 2 ) ) ; $ B = hexdec ("0x." substr ($ pixels [$ index], 6, 2)); imagecolorallocate ( $image , $r , $g , $b ) ; $ Color = imagecolorallocate ($ image, $ r, $ g, $ b); $image , $x , $y , $color ) ; imagesetpixel ($ image, $ x, $ y, $ color); $ Index + +; } } / / Write image (JPG - but you can use a different format) on the disk / server $image , "immagine.jpg" ) ; imagejpeg ($ image, "image.jpg"); $image ) ; // libero tutto imagedestroy ($ image) / / free all |
We will return shortly on this issue by proposing other solutions ... ![]()










Hi!
I would like make better my SQL capabilities.
The 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 designer contacts?
The above code is workiing perfectelly if we are exporting the SWF height and 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 a bitmap Any more than 500 × 500 pixels from Flash?
@ Uday: please check your php settings. Could be some timeout setting too low. To send bitmap pixels to the server in POST mode can take Several minutes to process.