给你点提示
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure FastAntiAliasPicture(orig_bmp,big_bmp,out_bmp: TBitmap);
varconst
MaxPixelCount = 32768;
type
pRGBArray = ^TRGBArray;
TRGBArray = array[0..MaxPixelCount - 1] of TRGBTriple;
x, y, cx, cy: integer;
totr, totg, totb: integer;
Row1, Row2, Row3, DestRow: pRGBArray;
i: integer;
begin
for y := 0 to orig_bmp.Height - 1 do
begin
cy := y * 3;
Row1 := big_bmp.ScanLine[cy];
Row2 := big_bmp.ScanLine[cy + 1];
Row3 := big_bmp.ScanLine[cy + 2];
DestRow := out_bmp.ScanLine[y];
//扫描三行象素
for x := 0 to orig_bmp.Width - 1 do
begin
cx := 3 * x;
totr := 0;
totg := 0;
totb := 0;
for i := 0 to 2 do
begin
// 算出总的红色分量
totr := totr + Row1[cx + i].rgbtRed
+ Row2[cx + i].rgbtRed
+ Row3[cx + i].rgbtRed;
// 算出绿色分量
totg := totg + Row1[cx + i].rgbtGreen
+ Row2[cx + i].rgbtGreen
+ Row3[cx + i].rgbtGreen;
// 算出总的蓝色分量
totb := totb + Row1[cx + i].rgbtBlue
+ Row2[cx + i].rgbtBlue
+ Row3[cx + i].rgbtBlue;
end;
DestRow[x].rgbtRed := totr div 9;
// 取平均后的红色分量
DestRow[x].rgbtGreen := totg div 9;
// 取平均后的绿色分量
DestRow[x].rgbtBlue := totb div 9;
// 取平均后的蓝色分量
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c:Tbitmap;
begin
a:=Tbitmap.Create;
b:=Tbitmap.Create;
c:=Tbitmap.Create;
a.PixelFormat:= pf24bit;
b.PixelFormat:= pf24bit;
c.PixelFormat:= pf24bit;
a.Height:=200;
a.Width:=200;
c.Height:=200;
c.Width:=200;
b.Height:=600;
b.Width:=600;
a.Canvas.Ellipse(10,10,140,180);
b.Canvas.Pen.Width:=3;
b.Canvas.Ellipse(10,10,140,180);
FastAntiAliasPicture(a,b,c);
canvas.Draw(0,0,c);
end;
end.