Today I needed to found a way to create bitmap data object from a display object. I found a solution in Flex Cookbook (http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=1682) and having this I improved it and made it simpler.
The code follows…
public function makeBitmap(myDO:DisplayObject):BitmapData { var myBD:BitmapData = new BitmapData(myDO.width, myDO.height); myBD.draw(myDO); return myBD; }
This is all of it. Isn’t is simple?
Tags: ActionScript, bitmap
This post was written by Andrei Ionescu
Views: 2058



















In Flex you can also use the ImageSnapshot class which makes it even easier
Don’t forget that using this method you will loose any scaling, rotation or alpha that might exist on the original display object. To preserve those simply inspect the scaleX/Y/rotation values of the original DO and then build a matrix which you pass as the 2nd parameter to draw. Also add smoothing if you need!
[...] Create bitmap data object from a display object http://www.flexer.info/2008/08/20/how-to-make-a-bitmapdata-from-a-displayobjectuicomponent/ [...]
[...] Create bitmap data object from a display object http://www.flexer.info/2008/08/20/how-to-make-a-bitmapdata-from-a-displayobjectuicomponent/ [...]
You write very well.