type
PixArray = Array [0..2] of Byte;
//
procedure Antialiasing(Bitmap: TBitmap; Rect: TRect; Percent: Integer);
var
pix, prevscan, nextscan, hpix: ^PixArray;
l, p: Integer;
R, G, B: Integer;
R1, R2, G1, G2, B1, B2: Byte;
begin
Bitmap.PixelFormat := pf24bit;
with Bitmap.Canvas do
begin
Brush.Style := bsclear;
for l := Rect.Top to Rect.Bottom - 1 do
begin
pix:= Bitmap.ScanLine[l];
if l <> Rect.Top then prevscan := Bitmap.ScanLine[l-1]
else prevscan := nil;
if l <> Rect.Bottom - 1 then nextscan := Bitmap.ScanLine[l+1]
else nextscan := nil;
for p := Rect.Left to Rect.Right - 1 do
begin
R1 := pix^[2];
G1 := pix^[1];
B1 := pix^[0];
if p <> Rect.Left then
begin
//Pixel links
//Pixel left
hpix := pix;
dec(hpix);
R2 := hpix^[2];
G2 := hpix^[1];
B2 := hpix^[0];
if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
begin
R := R1 + (R2 - R1) * 50 div (Percent + 50);
G := G1 + (G2 - G1) * 50 div (Percent + 50);
B := B1 + (B2 - B1) * 50 div (Percent + 50);
hpix^[2] := R;
hpix^[1] := G;
hpix^[0] := B;
end;
end;
if p <> Rect.Right - 1 then
begin
//Pixel rechts
//Pixel right
hpix := pix;
inc(hpix);
R2 := hpix^[2];
G2 := hpix^[1];
B2 := hpix^[0];
if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
begin
R := R1 + (R2 - R1) * 50 div (Percent + 50);
G := G1 + (G2 - G1) * 50 div (Percent + 50);
B := B1 + (B2 - B1) * 50 div (Percent + 50);
hpix^[2] := R;
hpix^[1] := G;
hpix^[0] := B;
end;
end;
if prevscan <> nil then
begin
//Pixel oben
//Pixel up
R2 := prevscan^[2];
G2 := prevscan^[1];
B2 := prevscan^[0];
if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
begin
R := R1 + (R2 - R1) * 50 div (Percent + 50);
G := G1 + (G2 - G1) * 50 div (Percent + 50);
B := B1 + (B2 - B1) * 50 div (Percent + 50);
prevscan^[2] := R;
prevscan^[1] := G;
prevscan^[0] := B;
end;
Inc(prevscan);
end;
if nextscan <> nil then
begin
//Pixel unten
//Pixel down
R2 := nextscan^[2];
G2 := nextscan^[1];
B2 := nextscan^[0];
if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
begin
R := R1 + (R2 - R1) * 50 div (Percent + 50);
G := G1 + (G2 - G1) * 50 div (Percent + 50);
B := B1 + (B2 - B1) * 50 div (Percent + 50);
nextscan^[2] := R;
nextscan^[1] := G;
nextscan^[0] := B;
end;
Inc(nextscan);
end;
Inc(pix);
end;
end;
end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
Antialiasing(Image1.Picture.Bitmap,
Rect(
0, // HIER KANN DER BEREICH FÜR DIE HÖHE INERHALB DES BILDES ANGEGEBEN WERDEN
0, // HIER KANN DER BEREICH FÜR DIE BREITE INERHALB DES BILDES ANGEGEBEN WERDEN
Image1.Picture.Bitmap.Width, Image1.Picture.Bitmap.Height),
15); // HIER WIRD PROZENTUAL DIE ANTIALIASING BERECHNUNG DEFINIERT
end;
Keine Kommentare:
Kommentar veröffentlichen