Package | flash.filters |
Class | public class ColorMatrixFilter |
Inheritance | ColorMatrixFilter BitmapFilter Object |
Player version: | Flash Player 8 |
The use of filters depends on the object to which you apply the filter:
filters
property. Setting the filters
property of an object does not modify the object and can be undone by clearing the filters
property.BitmapData.applyFilter()
method. Calling applyFilter()
on a BitmapData object takes the source BitmapData object and the filter object and generates a filtered image as a result.You can also apply filter effects to images and video at authoring time. For more information, see your authoring documentation.
If you apply a filter to a movie clip or button, the cacheAsBitmap
property of the movie clip or button is set to true
. If you clear all filters, the original value of cacheAsBitmap
is restored.
The following formulas are used, where a[0] through a[19] correspond to entries 0 through 19 in the 20-element array property matrix:
redResult = a[0] * srcR + a[1] * srcG + a[2] * srcB + a[3] * srcA + a[4] greenResult = a[5] * srcR + a[6] * srcG + a[7] * srcB + a[8] * srcA + a[9] blueResult = a[10] * srcR + a[11] * srcG + a[12] * srcB + a[13] * srcA + a[14] alphaResult = a[15] * srcR + a[16] * srcG + a[17] * srcB + a[18] * srcA + a[19]
This filter separates each source pixel into its red, green, blue, and alpha components as srcR, srcG, srcB, srcA. As a final step, it combines each color component back into a single pixel and writes out the result.
The calculations are performed on unmultiplied color values. If the input graphic consists of premultiplied color values, those values are automatically converted into unmultiplied color values for this operation.
The following two optimized modes are available.
Alpha only. When you pass to the filter a matrix that adjusts only the alpha component, as shown here, the filter optimizes its performance:
1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 N 0 (where N is between 0.0 and 1.0)
Faster version. Available only with SSE/Altivec accelerator-enabled processors such as Pentium 3 and later, and Apple G4 and later). The accelerator is used when the multiplier terms are in the range -15.99 to 15.99 and the adder terms a[4], a[9], a[14], and a[19] are in the range -8000 to 8000.
A filter is not applied if the resulting image would exceed 2880 pixels in width or height. For example, if you zoom in on a large movie clip with a filter applied, the filter is turned off if the resulting image reaches the 2880-pixel limit.
import flash.filters.BitmapFilter; import flash.filters.ColorMatrixFilter; var image:MovieClip = this.attachMovie("YourImageLinkage", "YourImage", this.getNextHighestDepth()); image.cacheAsBitmap = true; var listener:Object = new Object(); listener.image = image; listener.onMouseMove = function() { var xPercent:Number = 1 - (_xmouse/Stage.width); var yPercent:Number = 1 - (_ymouse/Stage.height); var matrix:Array = new Array(); matrix = matrix.concat([yPercent, 0, 0, 0, 0]); // red matrix = matrix.concat([0, xPercent, 0, 0, 0]); // green matrix = matrix.concat([0, 0, xPercent, 0, 0]); // blue matrix = matrix.concat([0, 0, 0, 1, 0]); // alpha var filter:BitmapFilter = new ColorMatrixFilter(matrix); image.filters = new Array(filter); } Mouse.addListener(listener); listener.onMouseMove();
See also
Property | ||
---|---|---|
matrix : Array
An array of 20 elements for 4 x 5 color transform.
|
Properties inherited from class Object | |
---|---|
__proto__, __resolve, constructor, prototype |
Method | ||
---|---|---|
ColorMatrixFilter(matrix:Array)
Initializes a new ColorMatrixFilter instance with the specified parameters.
|
||
Returns a copy of this filter object.
|
Methods inherited from class BitmapFilter | |
---|---|
clone |
Methods inherited from class Object | |
---|---|
addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch |
matrix | property |
public var matrix:Array
Player version: | Flash Player 8 |
An array of 20 elements for 4 x 5 color transform.
matrix
property. The matrix
property cannot be changed by directly modifying its value (for example, clonedFilter.matrix[2] = 1;
). Instead, you must get a reference to the array, make the change to the reference, and reset the value using clonedFilter.matrix = changedMatrix
. import flash.filters.ColorMatrixFilter; var matrix:Array = new Array(); matrix = matrix.concat([1, 0, 0, 0, 0]); // red matrix = matrix.concat([0, 1, 0, 0, 0]); // green matrix = matrix.concat([0, 0, 1, 0, 0]); // blue matrix = matrix.concat([0, 0, 0, 1, 0]); // alpha var filter:ColorMatrixFilter = new ColorMatrixFilter(matrix); trace("filter: " + filter.matrix); var changedMatrix:Array = filter.matrix; changedMatrix[2] = 1; filter.matrix = changedMatrix; trace("filter: " + filter.matrix);
ColorMatrixFilter | () | constructor |
public function ColorMatrixFilter(matrix:Array)
Player version: | Flash Player 8 |
Initializes a new ColorMatrixFilter instance with the specified parameters.
Parametersmatrix:Array — An array of 20 elements arranged in a 4 x 5 matrix. |
clone | () | method |
public function clone():ColorMatrixFilter
Player version: | Flash Player 8 |
Returns a copy of this filter object.
ReturnsColorMatrixFilter —
A new ColorMatrixFilter instance with all the same properties as the original one.
|
clone
method. The matrix
property cannot be changed directly (for example, clonedFilter.matrix[2] = 1;
). Instead, you must get a reference to the array, make the change, and reset the value using clonedFilter.matrix = changedMatrix
. import flash.filters.ColorMatrixFilter; var matrix:Array = new Array(); matrix = matrix.concat([1, 0, 0, 0, 0]); // red matrix = matrix.concat([0, 1, 0, 0, 0]); // green matrix = matrix.concat([0, 0, 1, 0, 0]); // blue matrix = matrix.concat([0, 0, 0, 1, 0]); // alpha var filter:ColorMatrixFilter = new ColorMatrixFilter(matrix); trace("filter: " + filter.matrix); var clonedFilter:ColorMatrixFilter = filter.clone(); matrix = clonedFilter.matrix; matrix[2] = 1; clonedFilter.matrix = matrix; trace("clonedFilter: " + clonedFilter.matrix);