Drawing Antialiased Shapes
Asked Answered
P

0

6

I'm try to improve some of the drawing that I'm doing in my project by provide antialiasing. I'm playing with a simple project using the Graphics32 Library instead of the standard delphi Canvas functions. I am testing with simple shapes and noticed a blurring affect and was wondering if it could be fixed.

procedure TForm1.FormPaint(Sender: TObject);
var
    Points : TArrayOfFixedPoint;
    ar: array [0 .. 6] of Tpoint;
begin
    // Antialiased Triangle
    SetLength(Points, 3);
    Points[0] := FixedPoint(20, 20);
    Points[1] := FixedPoint(20 + 100, 20 + 20);
    Points[2] := FixedPoint(20, 20 + 20);
    PolygonFS(self.mBitmap, FixedPointToFloatPoint(Points), clYellow32, pfAlternate, nil); // Draw Filled Polygon
    PolylineFS(self.mBitmap, FixedPointToFloatPoint(Points), clBlack32, true, 1); // Draw Outline

    self.mBitmap.DrawTo(self.Canvas.Handle, 0, 0);

    // Normal Triangle
    ar[0] := point(20, 150);
    ar[1] := point(20 + 100, 150 + 20);
    ar[2] := point(20, 150 + 20);
    ar[3] := point(20, 150);
    self.Canvas.Brush.Color := clYellow;
    self.Canvas.Polygon(slice(ar, 3));
end;

The antialiased triangle has a much smoother hypotenuse, but the two straight lines looks like they're blurred, which makes sense since it's antialiased. Is there a way to get the best of both worlds where the vertical and horizontal lines don't blend, while smoothing out the hypotenuse?

Edit: The version of Graphic32 I'm using is the top of the master branch from the Official Github Fork since the last release appears to be 1.9.1 from 2012.

Pubilis answered 21/11, 2016 at 5:34 Comment(7)
Obviously you could by drawing the centre as you do, then draw the hypotenuse aliased and the other two sides normally, using MoveTo/LineTo. But I am not convinced that this is the best of both worlds, even in this special case, because two line would look sharp and one fuzzy. Surely it is best for all 3 to be fuzzy?Landri
@Landri I have been thinking that drawing the lines individually would achieve the result I think I was looking for. I'll have to make an example later to see what it looks likePubilis
Have you tried playing with TAntialiasMode? I recall there are overloaded methods where you can specify aaMode. You did not say which version of GR32 you are using, so I can't say if it applies to your project.You could ofcourse also provide the missing parts of your test to make it more easy for those that would take the time to try and help you. In other words a MCVE.Cottonseed
@TomBrunberg I've updated the question to include information about which version of Graphics32 I'm using. Would these be the overloads you were talking about link I can't find these in the source itself (GR32_Polygons), but I may be looking in the wrong unitPubilis
Good news: Graphics32 has been updated last month (04.2017)Macaco
@BorlImpriceGoGearEmbaIdera cheers for that, I'll have to take a look and see what's changedPubilis
@ClaytonJohnson - not much. just some bugs fixed. make sure you donwnload from github and not from sourceforge!Macaco

© 2022 - 2024 — McMap. All rights reserved.