making things move as3阅读笔记 ---bitmapdata几个有用的操作函数

来源:互联网 发布:java rawurlencode 编辑:程序博客网 时间:2024/04/30 21:34

1. applyFilter(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, filter:BitmapFilter):void和generateFilterRect(sourceRect:Rectangle, filter:BitmapFilter):Rectangle

applyFilter取得一个源图像和一个滤镜对象,并生成过滤的图像。displayobject中有filter属性,而bitmapDATA若要使用滤镜则需此方法,当然bitmap继承自displayobject,含flter数组属性,故也可使用bitmap中的滤镜属性进行操作;

generateFilterRect()和applyFilter为计算使用了滤镜效果的rect;

2. clone()

拷贝bitmapdata并返回新的引用;

3. compare(otherBitmapData:BitmapData):Object

目标和本bitmapdata长宽相同,返回差值新bitmapdata;如果宽同高不同,返回-4;若高同宽不同,返回-3;判断为同一个对象,返回0;

4. copyChannel(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, sourceChannel:uint, destChannel:uint):void

只拷贝一个channel的值,用此函数,将red的值拷贝到自身blue和green的channel上,可以实现黑白图像效果;

5. draw(source:IBitmapDrawable, matrix:Matrix = null, colorTransform:ColorTransform = null, blendMode:String = null, clipRect:Rectangle = null, smoothing:Boolean = false):void

source 显示对象使用flash player矢量渲染器绘制到位图中;

如:import flash.display.Bitmap;

import flash.display.BitmapData;

import flash.text.TextField;

var tf:TextField = new TextField();

tf.text = "bitmap text";

var myBitmapData:BitmapData = new BitmapData(80, 20);

myBitmapData.draw(tf);

var bmp:Bitmap = new Bitmap(myBitmapData);

this.addChild(bmp);

6. fillRect(rect:Rectangle, color:uint):void和floodFill(x:int, y:int, color:uint):void

不同之处为floodFill为倾倒填充,类似于颜料桶;

7. lock()和unlock()

锁定图像,以使引用 BitmapData 对象的任何对象(如 Bitmap 对象)在此 BitmapData 对象更改时不会更新。若要提高性能,请在对 setPixel()setPixel32() 方法进行多次调用之前和之后使用此方法及 unlock() 方法。

8. merge(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, redMultiplier:uint, greenMultiplier:uint, blueMultiplier:uint, alphaMultiplier:uint):void

9. noise(randomSeed:int, low:uint = 0, high:uint = 255, channelOptions:uint = 7, grayScale:Boolean = false):void

生成随机杂点;

10. paletteMap(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, redArray:Array = null, greenArray:Array = null, blueArray:Array = null, alphaArray:Array = null):void

重新映射一个具有最多四组调色板数据(每个通道一组)的图像中的颜色通道值。

Flash Player 使用以下步骤生成结果图像:

  1. 计算了红色、绿色、蓝色和 Alpha 值后,将使用标准 32 位整数算法将它们相加在一起。
  2. 每个像素的红色、绿色、蓝色和 Alpha 通道值被分别提取为一个 0 到 255 的值。 使用这些值在相应的数组中查找新的颜色值:redArraygreenArrayblueArrayalphaArray。 这四个数组中的每一个都应包含 256 个值。
  3. 在检索了所有四个新通道值之后,它们会被组合成一个应用于像素的标准 ARGB 值。
  4. 您可以为多种效果(例如,常规调色板映射)使用此方法(采用一个通道并将其转换为假颜色图像)。 您也可以为各种高级颜色操作算法(例如,灰度系数、曲线、级别和量化)使用此方法。

根据颜色值作为下标,在数组中查找新的颜色值,替换,生成新的颜色;

11. perlinNoise(baseX:Number, baseY:Number, numOctaves:uint, randomSeed:int, stitch:Boolean, fractalNoise:Boolean, channelOptions:uint = 7, grayScale:Boolean = false, offsets:Array = null):void

生成perlin杂点图像。

您可以使用 Perlin 杂点函数来模拟自然现象和风景,例如,木材纹理、云彩或山脉。 在大多数情况下,Perlin 杂点函数的输出不会直接显示出来,而是用于增强其它图像并为其它图像提供伪随机变化。

简单的数字随机杂点函数通常生成具有粗糙的对比度点的图像。 这种粗糙的对比度在自然界中通常是找不到的。 Perlin 杂点算法混合了在不同的详细级别上进行操作的多个杂点函数。 此算法在相邻的像素值间产生较小的变化。

12.scroll(x:int, y:int):void

滚动像素,实际上和copy同一份bitmapData到xy点显示相同。

13. threshold(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, operation:String, threshold:uint, color:uint = 0, mask:uint = 0xFFFFFFFF, copySource:Boolean = false):uint

根据指定的阈值测试图像中的像素值,并将通过测试的像素设置为新的颜色值。

如:

var pt:Point = new Point(0, 0);

var rect:Rectangle = new Rectangle(0, 0, 200, 200);

var threshold:uint = 0x00800000;

var color:uint = 0x20FF0000;

var maskColor:uint = 0x00FF0000;

bmd2.threshold(bmd1, rect, pt, ">", threshold, color, maskColor, true);