基本原理:
以一个像素点为中心,取一个3*3大小的区域,以该区域中9个像素点的颜色平均值为该中心像素点着色
实例:
var
Form17: TForm17;
Map1:TBitmap;
implementation
{$R *.dfm}procedure TForm17.FormCreate(Sender: TObject);
begin
// Lb_R.Caption:='';
OpenDialog1.DefaultExt:=GraphicExtension(TBitmap);
OpenDialog1.Filter:=GraphicFilter(TBitmap);
if OpenDialog1.Execute then
begin
Map1:=TBitmap.Create;
Map1.LoadFromFile(OpenDialog1.FileName);
Image1.Picture.Bitmap:=Map1;
end;
end;
procedure TForm17.Button1Click(Sender: TObject);
var
xmax,ymax,i,j,m,n:integer;
r,g,b:integer;
temp:TColor;
begin
xmax:=Image1.Picture.Bitmap.Width-1;
ymax:=Image1.Picture.Bitmap.Height-1;
Label1.Caption:='柔化处理中,请稍后...';
Form17.Refresh;
ProgressBar1.Min:=0;
ProgressBar1.Max:=xmax;
ProgressBar1.Position:=0;
ProgressBar1.Step:=1;
Form17.Refresh;
for i:=1 to xmax-1 do
begin
ProgressBar1.StepIt;
for j:=1 to ymax-1 do
begin
r:=0;
g:=0;
b:=0;
for m:=i-1 to i+1 do
for n:=j-1 to j+1 do
begin
r:=r+GetRValue(Image1.Canvas.Pixels[m,n]);
g:=g+GetGValue(Image1.Canvas.Pixels[m,n]);
b:=b+GetBValue(Image1.Canvas.Pixels[m,n]);
end;
r:=r div 9;
g:=g div 9;
b:=b div 9;
Image1.Canvas.Pixels[i,j]:=RGB(r,g,b);
end;
end;
Image1.Refresh;
Label1.Caption:='柔化处理完成...';
end;