You want to change the value of some pixels in a bitmap, based on their current value.
Use the threshold() method of the BitmapData class.
The threshold() method is probably the most complex in the BitmapData API, but quite powerful once you understand how it works. The method uses two BitmapData objects:
destBitmap, which is the bitmap that will
sourceBitmap, which is the other bitmap
that gets passed in as a parameter. The method uses this bitmap’s
pixel data for its calculations.
The method compares each pixel in
sourceBitmap against a specified value,
using one of six comparison operators. If the comparison fails, the
corresponding pixel in
is set to a specified color value. If it passes the comparison, the
pixel is either not changed, or you have the option of copying over
sourceBitmap’s value for that
Here is the syntax for the method:
destBitmap.threshold(sourceBitmap, sourceRect, destPoint, operation, threshold, color, mask, copySource)
We’ve already covered
sourceBitmap. The next parameter,
sourceRect, is an instance of the flash.geom.Rectangle class. It defines what
portion of the
want to use for comparison. If you want to use the entire bitmap, you
can pass in
sourceBitmap.rect as a
value to this parameter.
destPoint parameter specifies the point in the
destBitmap at which the pixels
start to be affected. Picture the
sourceBitmap overlaid on
destBitmap, with its ...