Hi guys! I'm working on a Cad application using GDI+ API's and MFC.
I scale and translate the drawing using GDI+ tranformations and I use solid pen for drawing unselected geometries, dashed pen for selected ones.
All pens have a 0 width (so 1 pixel wide independently of the scale).
Until now I've always kept antialiasing on and everything seemed work ok but as I deactivate antialiasing (SetSmoothingMode(SmoothingModeNone)) all the arcs "small enough" (10 units or less of radius) start to appear poligonal, and with smaller arcs (radius < 1) they appear approximated as a triangle!
The problem occurs only with antialiasing turned off and with dashed pen (default or custom dashed makes no difference).
If i could have a screenshoot to see how much they are approximated, i can tell you if it is a normal thing or not. Remember that everything drawn from a PC is approximated up to a certain level, and when AA is off, its approximation is easier to notice.
Well, that's not completely normal. Anyways i cannot help you, i don't use GDI+... Try drawing yourself a circle using sin/cos...
This picture may help you: http://upload.wikimedia.org/wikipedia/commons/9/9d/Circle-trig6.svg
So you can set a fixed step of 1 pixel, and get your X position from sin() and your Y position from cos()
Like this:
1 2 3 4 5 6 7 8 9 10 11
void DrawCircle(COORD Position, unsignedint Radius)
{
for(unsignedint i = 0; i < (2*PI*100*Radius); i++)
{
unsignedint X = sin(i) * radius;
X += Position.X;
unsignedint Y = cos(i) * radius;
Y += Position.Y;
DrawPixel(sin(i),cos(i)); /* Your Drawing Pixel Function */
}
}
Or similar. I repeat, i know nothing about GDI+, and I'm a beginner in trig.
OT:
Yes I'm from Venice.
I know I can draw arcs by myself but I want to use as much library API as possible. We are refactoring our cad/cam application from old GDI management. We tried to use Direct2D but we need compatibility with WindowsXP (Direct2D works only with Win7 and Vista SP2 with platform update).
There are probably a lot of strategies to circumvent this problem:
- first of all keep antialiasing always on :), but this could be a problem with old and low performace PC
- the problem occours only when working with small arcs and high scale factor, so I can use a global scale conversion factor (say 1000) so that all geometries will be drawn sufficiently large (in GDI+ world units)
- I can avoid using ScaleTranform at all and tranform geometries by myself before drawing
These may solve the problem (I don't tried yet) but I really don't want to start hacking so simple tasks as drawing an arc.
I know that GDI+ is quite buggy, maybe this is a library bug, but It would be strange if no one found it before, so it's likely that I'm doing something wrong...