all groups > dotnet drawing api > july 2003 >
You're in the

dotnet drawing api

group:

Anti Aliasing kunundrum!


Anti Aliasing kunundrum! Mike in Paradise
7/29/2003 6:20:25 AM
dotnet drawing api:
I am building a control that is light rendering on a
rotating ball that moves as the mouse moves which means
each time the mouse moves each pixel in the control can
change. I have this in a bitmap using the SetPixel
command and it is working great except for Jagged Edges on
the outside of the ball.

I could not find any anti-aliasing methods within the
bitmap class.

I tried redoing the code with the Graphic command and
using Bob's method for setTing pixel by pixel but the
performance was just unacceptable.


Then I though I can render my ball into the bitmap, then
move the bitmap into a graphics object, set the anti-
aliasing smoothing and draw an eclipse around the edge of
the ball to give the smoothing on the outer edge and keep
performance. THis is the code.

Graphics graphics = Graphics.FromImage((Image)bitmap);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.DrawEllipse(new Pen(colorAmbient,1f),
13,
1,
ballSize.Width-1,
ballSize.Height-3);
RollerBallBox.Image= bitmap;

Works the first through the routine but then the Jaggies
are back and I am stumped. At what point is the Anti-
Aliasing done on the graphics object?

In order to keep performance up in the control I just keep
replacing a bitmap in a picture box on the control as the
mouse moves and am not repainting for each mouse move as
when I tried that it was just too slow.

When the ball is initially created or when options are
changed OnPaint is called which also redraws the ball. So
it seems to me that the Anti-Aliasing is being done only
during Paint events.

Can anyone give me a nudge in the right direction..

Thanks...


Performance Mike in Paradise
7/29/2003 7:16:58 AM
The motion of the ball is jerky as doing that amount of
drawing in the OnPaint seems to slow it down so you don't
get a nice smooth rotation of the ball at least I
counldn't get it to work well. Work like a charm
motionwise as is just that one little jagged edge problem.

[quoted text, click to view]
Re: Anti Aliasing kunundrum! Oscar Papel
7/29/2003 9:51:13 AM
[quoted text, click to view]

Why not then do all your drawing within OnPaint?

Oscar

Performance Mike in Paradise NL
7/29/2003 12:18:20 PM
The application is a graphical roller ball image use to
create, x,y,z vectors. When you click and move the mouse
the ball turns. It is a 3d ball with full light
rendering. If you have it at say 100,100 you have 10,000
pixels that you are changing the color one by one through
a light rendering and vector caclulation routine. When
this is in the paint event I couldn't get it perform. The
rendering was way behind the movement of the mouse and was
very slow.


[quoted text, click to view]
Re: Performance james
7/29/2003 2:24:18 PM
Maybe you should check out the DirectX 9 SDK. I think you will find much
better ways to do your rendering there. And it is much faster than GDI+.
james

[quoted text, click to view]

Re: Performance Bob Powell [MVP]
7/29/2003 8:30:45 PM
Hi,
You should be doing all your painting in the OnPaint. It's the Graphics
object that does all the antialiasing so whatever graphics you're using
needs to have the smoothing mode etc set.

If you're using CreateGraphics and doing your drawing from inside a timer
handler (looks ok but not recommended as an animation technique) for
example, you need to set-up all the smoothing mode parameters and so-on
yourself again.

--
Bob Powell [MVP]
C#, System.Drawing

Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Buy quality Windows Forms tools
http://www.bobpowell.net/xray_tools.htm

New Tips and Tricks include creating transparent controls
and how to do double buffering.

[quoted text, click to view]

AddThis Social Bookmark Button