| 包 | flash.filters |
| 类 | public final class DisplacementMapFilter |
| 继承 | DisplacementMapFilter BitmapFilter Object |
| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
滤镜的具体使用取决于要应用滤镜的对象:
filters 属性。设置对象的 filters 属性不会修改相应的对象,而清除 filters 属性可以删除相应的滤镜。
BitmapData.applyFilter() 方法。对 BitmapData 对象调用 applyFilter() 会取得源 BitmapData 对象和滤镜对象,并生成一个过滤后的图像。
如果对显示对象应用滤镜,则该显示对象的 cacheAsBitmap 属性值将设置为 true。如果清除所有滤镜,将恢复 cacheAsBitmap 的原始值。
此滤镜使用以下公式:
dstPixel[x, y] = srcPixel[x + ((componentX(x, y) - 128) * scaleX) / 256, y + ((componentY(x, y) - 128) *scaleY) / 256)
其中,componentX(x, y) 从 mapBitmap 属性获得 (x - mapPoint.x ,y - mapPoint.y) 处的 componentX 属性颜色值。
滤镜使用的映射图像会进行缩放,以匹配舞台缩放比例。当对象自身呈一定的比例时,它不会进行缩放。
此滤镜支持舞台缩放。但不支持常规缩放、旋转和倾斜。如果对象本身进行了缩放(如果将 scaleX 和 scaleY 属性设置为除 1.0 以外的其它值),滤镜效果将不进行缩放。只有用户在舞台上进行放大时它才会缩放。
另请参见
| 属性 | 定义方 | ||
|---|---|---|---|
| alpha : Number 指定对于超出范围的替换应用的 Alpha 透明度值。 | DisplacementMapFilter | ||
| color : uint 指定对于超出范围的替换应用什么颜色。 | DisplacementMapFilter | ||
| componentX : uint 说明在映射图像中使用哪个颜色通道来置换 x 结果。 | DisplacementMapFilter | ||
| componentY : uint 说明在映射图像中使用哪个颜色通道来置换 y 结果。 | DisplacementMapFilter | ||
![]() | constructor : Object
对类对象或给定对象实例的构造函数的引用。 | Object | |
| mapBitmap : BitmapData 包含置换映射数据的 BitmapData 对象。 | DisplacementMapFilter | ||
| mapPoint : Point 一个值,它包含目标显示对象的左上角相对于映射图像左上角的偏移量。 | DisplacementMapFilter | ||
| mode : String 滤镜模式。 | DisplacementMapFilter | ||
![]() | prototype : Object [静态]
对类或函数对象的原型对象的引用。 | Object | |
| scaleX : Number 用于缩放映射计算的 x 置换结果的乘数。 | DisplacementMapFilter | ||
| scaleY : Number 用于缩放映射计算的 y 置换结果的乘数。 | DisplacementMapFilter | ||
| 方法 | 定义方 | ||
|---|---|---|---|
DisplacementMapFilter(mapBitmap:BitmapData = null, mapPoint:Point = null, componentX:uint = 0, componentY:uint = 0, scaleX:Number = 0.0, scaleY:Number = 0.0, mode:String = "wrap", color:uint = 0, alpha:Number = 0.0) 用指定参数初始化 DisplacementMapFilter 实例。 | DisplacementMapFilter | ||
返回此滤镜对象的副本。 | DisplacementMapFilter | ||
![]() |
指示对象是否已经定义了指定的属性。 | Object | |
![]() |
指示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | |
![]() |
指示指定的属性是否存在、是否可枚举。 | Object | |
![]() |
设置循环操作动态属性的可用性。 | Object | |
![]() |
返回指定对象的字符串表示形式。 | Object | |
![]() |
返回指定对象的原始值。 | Object | |
| alpha | 属性 |
alpha:Number [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
指定对于超出范围的替换应用的 Alpha 透明度值。它被指定为 0.0 到 1.0 之间的标准值。例如,.25 设置透明度值为 25%。默认值为 0。如果 mode 属性设置为 DisplacementMapFilterMode.COLOR,则使用此属性。
public function get alpha():Number public function set alpha(value:Number):void| color | 属性 |
color:uint [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
指定对于超出范围的替换应用什么颜色。置换的有效范围是 0.0 到 1.0。值采用十六进制格式。color 的默认值为 0。如果 mode 属性设置为 DisplacementMapFilterMode.COLOR,则使用此属性。
public function get color():uint public function set color(value:uint):void| componentX | 属性 |
componentX:uint [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
说明在映射图像中使用哪个颜色通道来置换 x 结果。可能的值为 BitmapDataChannel 常数:
BitmapDataChannel.ALPHA
BitmapDataChannel.BLUE
BitmapDataChannel.GREEN
BitmapDataChannel.RED
public function get componentX():uint public function set componentX(value:uint):void另请参见
| componentY | 属性 |
componentY:uint [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
说明在映射图像中使用哪个颜色通道来置换 y 结果。可能的值为 BitmapDataChannel 常数:
BitmapDataChannel.ALPHA
BitmapDataChannel.BLUE
BitmapDataChannel.GREEN
BitmapDataChannel.RED
public function get componentY():uint public function set componentY(value:uint):void另请参见
| mapBitmap | 属性 |
mapBitmap:BitmapData [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
包含置换映射数据的 BitmapData 对象。
public function get mapBitmap():BitmapData public function set mapBitmap(value:BitmapData):voidTypeError — 设置时 BitmapData 为 null |
另请参见
| mapPoint | 属性 |
mapPoint:Point [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
一个值,它包含目标显示对象的左上角相对于映射图像左上角的偏移量。
public function get mapPoint():Point public function set mapPoint(value:Point):voidTypeError — 设置时 Point 为 null |
另请参见
| mode | 属性 |
mode:String [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
滤镜模式。可能的值为 DisplacementMapFilterMode 常数:
DisplacementMapFilterMode.WRAP -- 将置换值折返到源图像的另一侧。
DisplacementMapFilterMode.CLAMP -- 将置换值锁定在源图像的边缘。
DisplacementMapFilterMode.IGNORE -- 如果置换值超出了范围,则忽略置换并使用源像素。
DisplacementMapFilterMode.COLOR -- 如果置换值在图像之外,则替换 color 和 alpha 属性中的值。
public function get mode():String public function set mode(value:String):voidTypeError — 设置时 String 为 null | |
ArgumentError — 模式字符串不是有效类型之一 |
另请参见
| scaleX | 属性 |
scaleX:Number [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
用于缩放映射计算的 x 置换结果的乘数。
public function get scaleX():Number public function set scaleX(value:Number):void| scaleY | 属性 |
scaleY:Number [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
用于缩放映射计算的 y 置换结果的乘数。
public function get scaleY():Number public function set scaleY(value:Number):void| DisplacementMapFilter | () | 构造函数 |
public function DisplacementMapFilter(mapBitmap:BitmapData = null, mapPoint:Point = null, componentX:uint = 0, componentY:uint = 0, scaleX:Number = 0.0, scaleY:Number = 0.0, mode:String = "wrap", color:uint = 0, alpha:Number = 0.0)| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
用指定参数初始化 DisplacementMapFilter 实例。
参数mapBitmap:BitmapData (default = null) — 包含置换映射数据的 BitmapData 对象。 | |
mapPoint:Point (default = null) — 一个值,它包含目标显示对象的左上角相对于映射图像左上角的偏移量。 | |
componentX:uint (default = 0) —
说明在映射图像中使用哪个颜色通道来置换 x 结果。可能的值为 BitmapDataChannel 常数。
| |
componentY:uint (default = 0) —
说明在映射图像中使用哪个颜色通道来置换 y 结果。可能的值为 BitmapDataChannel 常数。
| |
scaleX:Number (default = 0.0) —
用于缩放映射计算的 x 置换结果的乘数。
| |
scaleY:Number (default = 0.0) —
用于缩放映射计算的 y 置换结果的乘数。
| |
mode:String (default = "wrap") — 滤镜模式。可能的值为 DisplacementMapFilterMode 常数。 | |
color:uint (default = 0) —
指定对于超出范围的替换应用什么颜色。置换的有效范围是 0.0 到 1.0。如果 mode 设置为 DisplacementMapFilterMode.COLOR,则使用此参数。
| |
alpha:Number (default = 0.0) —
指定对于超出范围的替换应用什么 Alpha 值。它被指定为 0.0 到 1.0 之间的标准值。例如,.25 设置透明度值为 25%。如果 mode 设置为 DisplacementMapFilterMode.COLOR,则使用此参数。
|
另请参见
| clone | () | 方法 |
override public function clone():BitmapFilter| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 Flash Player 9 |
返回此滤镜对象的副本。
返回BitmapFilter — 具有与原始实例相同的所有属性的新 DisplacementMapFilter 实例。 |
draw() 方法,该方法使用 Graphics 类的方法通过放射状渐变填充绘制一个正方形。请注意,graphics 是扩展 Sprite 的 DisplacementMapFilterExample 对象的属性。
createLabel() 方法,该方法创建显示 labelText 值的文本字段,并将其添加到显示列表。
createFilter() 方法,该方法执行以下操作:
filter 的变量。
getDisplacementMapFilter() 方法并将其返回值赋予 filter 变量。
filter 传递给 DisplacementFilterExample 对象(主类)的 filters 属性。
getBitmapFilter() 方法创建一个名为 mapBitmap 的 BitmapData 对象,并将 createBitmapData() 方法的结果赋予它。mapBitmap 对象以及其它变量定义了新的置换图滤镜。
createBitmapData() 方法创建新的 BitmapData 对象,该对象基于 DisplacementMapFilterExample 对象的当前内容。它基于 bitmapData 创建新位图,并将该位图添加到舞台。
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.filters.BitmapFilter;
import flash.filters.DisplacementMapFilter;
import flash.filters.DisplacementMapFilterMode;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.text.TextField;
public class DisplacementMapFilterExample extends Sprite {
private var bgColor:uint = 0xFFCC00;
private var size:uint = 200;
private var offset:uint = 90;
private var labelText:String = "Watch the text bend with the displacement map";
public function DisplacementMapFilterExample() {
draw();
createLabel();
createFilter();
}
private function createFilter():void {
var filter:BitmapFilter = getBitmapFilter();
filters = new Array(filter);
}
private function getBitmapFilter():BitmapFilter {
var mapBitmap:BitmapData = createBitmapData();
var mapPoint:Point = new Point(0, 0);
var channels:uint = BitmapDataChannel.RED;
var componentX:uint = channels;
var componentY:uint = channels;
var scaleX:Number = 0.5;
var scaleY:Number = -30;
var mode:String = DisplacementMapFilterMode.CLAMP;
var color:uint = 0;
var alpha:Number = 0;
return new DisplacementMapFilter(mapBitmap,
mapPoint,
componentX,
componentY,
scaleX,
scaleY,
mode,
color,
alpha);
}
private function draw():void {
var matrix:Matrix = new Matrix();
matrix.createGradientBox(size, size);
graphics.beginGradientFill(GradientType.RADIAL,
[0xFF0000, 0x0000FF],
[100, 100],
[55, 200],
matrix,
SpreadMethod.PAD);
graphics.drawRect(0, 0, size, size);
}
private function createBitmapData():BitmapData {
var bitmapData:BitmapData = new BitmapData(size, size, true, bgColor);
bitmapData.draw(this, new Matrix());
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = size;
addChild(bitmap);
return bitmapData;
}
private function createLabel():void {
var tf:TextField = new TextField();
tf.text = labelText;
tf.y = offset;
tf.width = size;
addChild(tf);
}
}
}