Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Form antialiasing

OxyzNOxyzN Member Posts: 60
Is it possible to apply an antialiasing effect on a form's edge? Using an alpha blending mask or something?

Comments

  • injektiloinjektilo Member Posts: 113
    heres the anti-aliasing code, for a bitmap:

    [code]
    var
    TotRed, TotGreen, TotBlue: Real;

    procedure TForm1.SpeedButton1Click(Sender: TObject);
    begin
    with Image1.Picture.Bitmap do
    begin
    Width:=100;
    Height:=100;
    Canvas.Brush.Color:=clwhite;
    Canvas.Fillrect(rect(0,0,100,100));
    Canvas.Pen.Color:=clblack;
    Canvas.Moveto(10,30);
    Canvas.Lineto(90,90);
    Canvas.Pen.Width:=2;
    Canvas.ellipse(25,40,45,60);
    Canvas.Font.name:='Times New Roman';
    Canvas.Font.size:=15;
    Canvas.Textout(5,5,'Hallo');
    end;
    Image2.Picture.bitmap:=AntiAliasing(Image1.picture.bitmap);
    end;

    function TForm1.AntiAliasing(Bitmap : TBitmap) : TBitmap;
    var
    x,y: integer;
    NewBitmap : TBitmap;
    Red, Blue, Green : integer;
    begin
    NewBitmap:=TBitmap.Create;
    NewBitmap.Assign(Bitmap);
    for x:=0 to Bitmap.Width-1 do
    begin
    for y:=0 to Bitmap.Height-1 do
    begin
    TotRed:=0; TotGreen:=0; TotBlue:=0;
    CountRGB(Bitmap.Canvas,x,y,2);
    CountRGB(Bitmap.Canvas,x-1,y,8);
    CountRGB(Bitmap.Canvas,x,y-1,8);
    CountRGB(Bitmap.Canvas,x+1,y,8);
    CountRGB(Bitmap.Canvas,x,y+1,8);
    NewBitmap.Canvas.Pixels[x,y]:=RGB(round(TotRed),round(TotGreen),round(TotBlue));
    end;
    end;
    result:=NewBitmap;
    end;

    procedure TForm1.CountRGB(ACanvas : TCanvas; x,y : Integer; Q: Byte);
    var
    K: LongInt;
    R, G, B: Integer;
    begin
    K:=ColorToRGB(ACanvas.Pixels[x,y]);
    B:=K shr 16;
    G:=(K shr 8) and $00FF;
    R:=K and $0000FF;
    TotRed:=TotRed+R/Q;
    TotGreen:=TotGreen+G/Q;
    TotBlue:=TotBlue+B/Q;
    end;
    [/code]

    now apply this to the edges, i'm sure someone will give you a hint on how to do that. my times up.



Sign In or Register to comment.