skip to main |skip to sidebar
显示标签为“图形处理”的博文。显示所有博文
显示标签为“图形处理”的博文。显示所有博文

2007-11-18

[AS3]高级图形处理(2)——老照片滤镜

照片的时间久了,就会出现褪色、模糊、杂色。

实现方法

褪色
使用ColorTransform。参数为new ColorTransform(0.7, 0.7, 0.7, 0x44, 0x33, 0x22)。
模糊
使用BlurFilter。参数为new BlurFilter(0.2, 0.2)。
添加杂色
使用BitmapData.noise($randomSeed, 0xee, 0xff, 7, true)。

核心代码

//Color Transform
outputBitmapData.colorTransform( sourceRect, new ColorTransform(0.7, 0.7, 0.7, 0x44, 0x33, 0x22) );
//Blur
outputBitmapData.applyFilter( outputBitmapData, sourceRect, destPoint, new BlurFilter(0.2, 0.2) );
//Noise
var noise:BitmapData = new BitmapData($width, $height, false);
noise.noise(0, 0xee, 0xff, 7, true);
outputBitmapData.draw(
noise,
new Matrix(1, 0, 0, 1, destPoint.x, destPoint.y),
null,
BlendMode.MULTIPLY
);

完整代码下载

2007-10-28

[AS3]高级图形处理(1)——自定义颜色比率的噪音(Noise)

一般制作线性噪音(0~255之间呈线性分布的噪音)很简单。使用BitmapData.noise()即可。

但要求产生的噪音当中,红色占10%、绿色占10%、蓝色占80%该怎么办?没有现成的方法可以用。但这类噪声却很有用,比如游戏地图的随机生成、制作宇宙的繁星等。

其实很简单!可以使用BitmapData.pixelDissolve()。BitmapData.pixelDissolve()是用来溶解像素,制造马赛克的过渡效果的。但它还可以制造噪音!

代码:

package advancedflex.display.images {
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;

public class ImageRandom {

public static function customColorNoise(
src:BitmapData,
sourceRect:Rectangle,
colors:Array,
ratios:Array,
randomSeed:int = 0):int
{
if(colors.length != ratios.length) {
throw new ArgumentError("colors.length != ratios.length.")
}
if(!src) {
throw new ArgumentError("src is null.")
}
var length:int = colors.length;
var s:int = src.width * src.height;
for(var i:int = 0; i < length; i++) {
ratios[i] = s*ratios[i];
}
return customColorNoize2(src, sourceRect, colors, ratios, randomSeed);
}

public static function customColorNoize2(
src:BitmapData,
sourceRect:Rectangle,
colors:Array,
numPixels:Array,
randomSeed:int = 0):int
{
if(colors.length != numPixels.length) {
throw new ArgumentError("colors.length != numPixels.length.")
}
if(!src) {
throw new TypeError("Src must not be null.");
}
var length:int = colors.length;
var point:Point = new Point(sourceRect.x, sourceRect.y)
for(var i:int = 0; i < length; i++) {
randomSeed = src.pixelDissolve(src, sourceRect, point, randomSeed, numPixels[i], colors[i]);
}
return randomSeed;
}
}
}