Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

8. Bitmaps > Drawing a Display Object to a Bitmap

Drawing a Display Object to a Bitmap


You have some graphical content in a sprite or other display object and want to draw that to a bitmap.


Use the BitmapData class’s draw() method to draw the content onto the bitmap.


When you first create a BitmapData, it is simply a blank rectangle of whatever color you specified. You may have some existing graphic content in a movie clip, sprite, or other display object that you would like to draw to the new bitmap. The draw() method allows you to do just this. You pass the object you want to draw into the draw() method of the BitmapData you want to draw it onto. You can also pass an instance of the flash.geom.Matrix class to the method. The Matrix class allows you to scale, rotate, translate, or skew the object’s graphics before they are drawn. This parameter is optional, but if you need to use later parameters and don’t want to transform the object, just pass null. You can also optionally pass a ColorTransform object, which alters the color of the object before it is drawn. See Recipe 10.1 for information on ColorTransforms. The following example draws a sprite, named _sprite, into a BitmapData named bitmap, with no transformation:


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free 10-Day Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint