May 10, 2024, 10:38:58 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


anti-aliased lines and curves

Started by LarryMc, May 10, 2009, 10:15:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

May 10, 2009, 10:15:57 PM Last Edit: May 10, 2009, 10:24:34 PM by Larry McCaughn
Anyone have a simple explanation of how to draw anti-aliased lines (smooth lines) and curves instead of them being jagged-pixel based lines?

Like the ones below.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ficko

Hi Larry!

There is a link with a "C" algo can do the job for you.

http://courses.ece.illinois.edu/ece390/archive/archive-f2000/mp/mp4/anti.html

More speedy would be to use GDI  Plus flat API with "SetSmoothingMode:SmoothingModeAntiAlias=...."

Regards,
Ficko

Dennisc

Nice link Ficko - Good luck Larry - looks like a challenge! :)
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

LarryMc

Quote from: Ficko on May 10, 2009, 11:20:20 PM
More speedy would be to use GDI  Plus flat API with "SetSmoothingMode:SmoothingModeAntiAlias=...."

Ficko
Do you happen to have an example of how to incorporate the above into my existing WM_PAINT handler that is using a compatibleDC.

I found (on the old forums) how to GdiplusStartup and GdiplusShutdown.
I just don't know how much of my existing selectobject, etc. code would still be good and what I would have to change.

Any help would be appreciated.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ficko

I wrote a sample off the cough. 8)

I hope it helps.

Regards,
Ficko

LarryMc

Ficko,

Nice example.

Tells me exactly what I needed to know; for now.

Thanks

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

within a given WM_PAINT/@IDPAINT will GDI+ drawing commands honor a non-GDI+ clipping region?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

Larry, yes:
CASE @IDPAINT
Hdc = GetHDC(MainW)
HRGN region = CreateRectRgn(300,300,400,400)
SelectClipRgn(Hdc, region)

GdipCreateFromHDC
' [...]
GdipDeleteGraphics

SelectClipRgn(Hdc, 0)
DeleteObject(region)
ReleaseHDC MainW,Hdc

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

I know I have to call  GdiplusStartup before using any gdiplus functions and when I'm through I need to call GdiplusShutdown.

If I'm doing that inside a custom control (for each instance of the control) will that cause problems?

Or is it a once per application thing; which would place those commands outside my custom control?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Been doing some reading.

It appears that I can put GdiplusStartup in the WM_CREATE handler of my custom control and store the returned token in a prop.

Then in my WM_DESTROY handler I can retrieve the token and call GdiplusShutdown.

Can anyone confirm that?

Will I take a noticeable speed hit?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ficko

Hi Larry!

You should put "GdiplusStartup" at the Beginning of the program.
This is a common practice from several reasons.

1.)
GDI+ is "only" standard since Windows XP so you have to catch missing installations.
His future is uncertain.
MS seemingly abandoned it’s development in 2001.
There are lots of half implementations in the dll itself.
You can find functions on MSDN nicely explained but not implemented.
The biggest drawback is the partially implemented handlings of indexed bitmaps.

2.)
If your program get complex you may â€Ã...“jump overâ€Ã, the initialization and your program will crash by trying to call any GDI+ functions.

There is what you need to know about GDI+ if you wanna use it:

It is the strangest implementation MS ever managed to fabricate.
It is kind of OOP but implemented in API-s and MS supplies a wrapper collection if you properly wanna use it from â€Ã...“Câ€Ã, type languages.

Trough the â€Ã...“flat APIâ€Ã, you should NOT use it!
-This is what MS says not I do.- ;)

So the question remains why they did this implementation at all?! ;D
Of course you have no choice but to use the "flat API" if you wanna access the methods from other type of languages.

Due to being OOP it’s deals with objects in his interaction.
So you can imagine the difficulty to using APIs to access member variables and methods.

The most difficulty is to find the proper place to free up objects.
Since objects can get inherited etcâ€Ã,¦ you can’t just free them up after you don’t use them since you don’t know that GDI+ itself may still use them.
That something you have to find out by experience. :o

For exemplar:
You clone an Image object.
You may free the old object if you use "flip" on the new object but you can’t free the old object if you use "rotate" or "resize" because GDI+ use the â€Ã...“originalâ€Ã, object
as reference to sometimes achieve better results.
This â€Ã...“keepingâ€Ã, the old objects alive can go through even on objects transformed from old GDI to GDI+.

I hope I didn’t discourage you I just want to give you the proper perspective with what type of beast you are trying to deal with. ;D

Regards,
Ficko