Bitmap and Bitmapdata

Source: Internet
Author: User
Tags addchild

A Bitmap object can be shared among several Bitmap objects.BitmapDataReference, not related to conversion or rotation attributes.
Because multiple Bitmap objects that reference the same BitmapData object can be created, multiple display objects can use the same complex BitmapData object,
WhileNo memory overhead is generated because each Display object instance uses a BitmapData object..

Example 1: create 500 bitmaps. Each bitmap uses the memory of BitmapData referenced differently.

Import flash. display. bitmapData; import flash. display. bitmap; import flash. system. system; // print the initial memory trace ("when idle:" + System. totalMemory/1000 + "k"); var bmp dt: BitmapData; for (var I: int = 0; I <500; I ++) {// each time a new bitmapData is sent to bitmap bmp = new BitmapData (100,100, false, 0 xffccdd); var bmp: Bitmap = new Bitmap (bmp DT); addChild (bmp) bmp. x = I + 3; bmp. y = I + 3;} trace ("memory after creation:" + System. totalMemory/1000 + "k ");

Result:
Memory at idle time: 34328.576 KB
Memory size after creation: 55169.024 KB

Example 2: create 500 bitmaps. Each bitmap uses a reference of the same BitmapData.

Import flash. display. bitmapData; import flash. display. bitmap; import flash. system. system; // print the initial memory trace ("when idle:" + System. totalMemory/1000 + "k"); var bmp dt: BitmapData = new BitmapData (100,100, false, 0 xffccdd); for (var I: int = 0; I <500; I ++) {var bmp: Bitmap = new Bitmap (bmp DT); addChild (bmp) bmp. x = I + 3; bmp. y = I + 3;} trace ("memory after creation:" + System. totalMemory/1000 + "k ");

Result:
Memory at idle time: 34373.632 KB
Memory size after creation: 34799.616 KB

Pixel closeness and Smoothness

Bmp. smoothing = true; blur when bitmap is scaled. Using Bitmap. smoothing = true; will make the image smoother and more natural,It will consume more performance.
Apply Filter
When smoothing is set to true, bitmap rendering is slower than when smoothing is set to false.

Import flash. display. bitmapData; import flash. geom. rectangle; import flash. geom. point; import flash. filters. blurFilter; import flash. display. bitmap; // create bitmapDatavar bmp dt: BitmapData = new BitmapData (80, 30, false, 0 xffccdd); // create a Rectangle which will be specified to the bitmapdata coordinate var rect: rectangle = new Rectangle (20, 10, 40, 10); // fill the color of the region with the BMP. fillRect (rect, 0x0033ff); // obtain the coordinate var pt: Point = new Point (rect. left, rect. top); var blFilter: BlurFilter = new BlurFilter (8, 8, 1); bmp dt. applyFilter (bmp DT, rect, pt, blFilter); var bmp: Bitmap = new Bitmap (bmp DT); addChild (bmp );

 

Filter
Filter and bitmap cache: To apply a filter to a display object, you must enable the bitmap cache of the object. When a filter is applied to a display object whose cacheAsBitmap attribute is set to false, Flash Player automatically sets the value of the cacheAsBitmap attribute of the object to true. If you delete all the filters in the display object, Flash Player resets the cacheAsBitmap attribute to the last value.
Change Filter at run time: if one or more filters have been applied to the Display object, other filters cannot be added to the filters attribute array. To add or change this set of filters to be applied, you need to create a copy of the entire filter array and then modify the (temporary) array. Then, assign the array to the filters attribute of the display object so that the filter can be applied to the object.
Filter Example:

Var bmp DT: BitmapData = new BitmapData (100,100, true, 0 xffccddee); var bmp: Bitmap = new Bitmap (bmp); addChild (bmp); var filter: blurFilter = new BlurFilter (10, 10, 1); // declare a rectangel coordinate as the absolute coordinate and region var rect: Rectangle = new Rectangle (50, 50, 50, 50); var p: point = new Point (50, 50 );//Fill color is required; otherwise, the filter is invalid.Bmp dt. fillRect (rect, 0xffFF0000); bmp dt. applyFilter (bmp DT, rect, p, filter); colorTransform example: var bmd1: BitmapData = new BitmapData (100,100, true, 0 xffffccdd); var bmp: bitmap = new Bitmap (bmd1); addChild (bmp); var clorTran: ColorTransform = new ColorTransform (); // set the color conversion transparency to 0.7clorTran.alphaMultiplier = 0.7; var rect: rectangle = new Rectangle (50, 50, 20, 20); // set colorTranformbmd1.colorTransform (rect, clorTran) for Bitmapdata );

Copy pixels

Import flash. display. bitmap; import flash. display. bitmapData; import flash. geom. rectangle; import flash. geom. point; // target Bitmapdata to be copied var bmd1: BitmapData = new BitmapData (40, 40, false, 0x000000FF); var bmd2: BitmapData = new BitmapData (80, 40, false, 0x0000CC44); // mark bmd1.setPixel (15,15, 0x00ff0000) for the original Bitmapdata; var rect: Rectangle = new Rectangle (10, 10, 10, 10); var pt: point = new Point (30, 10); // copy the rect region of the Bitmapdata source to bmd2.copyPixels (bmd1, rect, pt) in the pt; var bm1: bitmap = new Bitmap (bmd1); this. addChild (bm1); var bm2: Bitmap = new Bitmap (bmd2); this. addChild (bm2); bm2.x = 50;

Draw ()
BitmapData. draw (source: IBitmapDrawable): void
The DisplayObject and BitmapData classes implement the IBitmapDrawable interface.

FloodFill is similar to the paint bucket in flash.

Var bmp dt: BitmapData = new BitmapData (200,200, false, 0xff0000); var rect: Rectangle = new Rectangle (100,100,); bmp dt. fillRect (rect, 0x00ff00); rect. x = 50; rect. y = 50; bmp dt. fillRect (rect, 0x0000ff); rect. x = 100; rect. y = 100; bmp dt. fillRect (rect, 0xff00ff); // floodFill is equivalent to the paint bucket dumping function bmp dt. floodFill (90,90, 0 xffccee) var bmp: Bitmap = new Bitmap (bmp DT); addChild (bmp );

GetPixels (rectangle)
Generates a byte array from the rectangle area of the pixel data. Writes an unsigned integer (32-bit unmultiplied pixel value) to a byte array for each pixel.

Import flash. display. bitmapData; import flash. geom. rectangle; import flash. display. bitmap; import flash. utils. byteArray; var BMI: BitmapData = new BitmapData (. width,. height, true); bone density. draw (a); var bounds: Rectangle = new Rectangle (0, 0, BMI. width, BMI. height); // BitmapData. getPixels (rectangel): ByteArray obtains a Rectangle binary data var pixels: ByteArray = bone density. getPixels (bounds); trace (pixels)

// When there are too many threads, there are too many threads, too many threads
When there are too many threads, there are too many threads, too many threads.
When there are too many threads, there are too many threads, too many threads.
When there are too many threads, there are too many threads, too many threads.
Please refer to the following link for more information:
3 then 3 then 3 then 3 then 3 then 3 then 3 then 3 then 3 then 3 then
3 bytes 3 bytes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.