Graphics DrawOval and rough edges with Antialias set to True

I’m not normally involved with drawing graphics within code, but I’ve just run into a really ugly situation regardless of the antialias setting for the graphics object.

Using the following code in a 172x172 canvas under Windows, the resulting circle values are very ragged.

  Dim a As New ArcShape
  Dim o As New OvalShape
  Dim r As New RectShape
  Dim oColor As Color = &c5873AD00
  
  Dim thePercent As Double = .42
  Dim theSlice As Double = 360 * thePercent
  Dim theSliceColor As Color
  
  o.Width = 160
  o.Height = 160
  o.FillColor = oColor
  g.DrawObject o, 80, 80
  
  If thePercent > .90 Then
    theSliceColor = &cB85F5800
  ElseIf thePercent > .80 Then
    theSliceColor = &cFFD26500
  Else
    theSliceColor = &c7C9E7900
  End If
  
  a.ArcAngle = theSlice * (acos(-1)/180)
  a.StartAngle = -1.57
  a.Width = 160
  a.Height = 160
  a.FillColor = theSliceColor
  g.DrawObject a, 80, 80

Is there a fix for this that I’ve missed?

Is App.UseGDIPlus set to True?

You may draw at 4 times the size on a picture buffer and scale to paint. This gives a better result :

[code] app.UseGDIPlus = True
Dim Scratch as new Picture(g.width4, g.height4)
Dim gg as graphics = Scratch.graphics
Dim a As New ArcShape
Dim o As New OvalShape
Dim r As New RectShape
Dim oColor As Color = &c5873AD00

Dim thePercent As Double = .42
Dim theSlice As Double = 360 * thePercent
Dim theSliceColor As Color

o.Width = 1604
o.Height = 160
4
o.FillColor = oColor
gg.DrawObject o, 804, 804

If thePercent > .90 Then
theSliceColor = &cB85F5800
ElseIf thePercent > .80 Then
theSliceColor = &cFFD26500
Else
theSliceColor = &c7C9E7900
End If

a.ArcAngle = theSlice * (acos(-1)/180)
a.StartAngle = -1.57
a.Width = 1604
a.Height = 160
4
a.FillColor = theSliceColor
gg.DrawObject a, 804, 804
g.drawpicture(scratch, 0, 0, g.width, g.height, 0, 0, scratch.width, Scratch.height)
[/code]

I could have sworn that I’d enabled GDIPlus …

The combination of that and Michel’s scaling option has really cleaned it up.

Thanks to both of you!

I must share a big thanks again to @Michel Bujardet for that answer. I’ve implemented this scaling mechanism for all of my drawn graphics and everything that I draw in that manner now looks much more professional.

@Paul Lefebvre - it might be a good idea to incorporate this concept into the Graphics.DrawPicture documentation examples.

[quote=205785:@Tim Jones]I must share a big thanks again to @Michel Bujardet for that answer. I’ve implemented this scaling mechanism for all of my drawn graphics and everything that I draw in that manner now looks much more professional.

@Paul Lefebvre - it might be a good idea to incorporate this concept into the Graphics.DrawPicture documentation examples.[/quote]

You’re welcome. Glad it works for you :slight_smile:

I need to pick up this topic again. The general scale factor of 4 is good but won’t work always. If you have objects with 32x32 for instance you need a higherscale factor to have the object receive antialias. So as for an 32x32 object the factor is about 14x.
Try it out with with above code or just set it to 100 x 100 or below but >110x110 should be fine though.