2

I want to manually antialias the output of GDI drawing functions on Windows. Each drawing function is rendered onto its own image and then blitted back (so alpha blending can work, as GDI doesn't do that natively), so the image has only two colors: transparent and the drawing color.

My question is simple: is there a way to antialias an existing line, circle, text, etc. drawn after the fact by hand (in a loop)?

I found this but I have no idea how it works, or if it even does work.

I'd rather not reimplement the drawing primitives myself; if I did that then I wouldn't need to be using GDI. I already have an alpha premultiplication loop; can I do the antialiasing there?

Update 23 September 2014/Alternate Question - there's this CodeProject article which suggests using HALFTONE blit stretching, however the GDI AlphaBlend() API does not support it, and I'm not sure if the output of using a third image for doing the halftone resize will be properly alpha-premultiplied if the input color is; is it?

  • 1
    You may be looking for a Convolution - by far the easiest way to implement anti-aliasing. – OldCurmudgeon Sep 22 '14 at 16:31
  • So wait, for this, would I take the average of each component value in the eight surrounding pixels and the pixel at (x,y) as the convolved value? Should I only do this for transparent pixels? – andlabs Sep 22 '14 at 17:50
  • Whatever applies best to your problem space - try here for some more general ideas. – OldCurmudgeon Sep 22 '14 at 18:55
  • Well I tried a few convolution matrices but I can't seem to get an effect other than blurring everything (including horizontal/vertical lines), which I don't want :S – andlabs Sep 23 '14 at 1:34
  • Ok, oddball comment here: is WPF an option? And no, I don't mean the XAML, bindings, etc. but more the lower-level render context. I think you may find it's richer composition model (built on milcore+DirectX vs. GDI) a better fit depending on your application... – J Trana Sep 25 '14 at 4:49
1

Technically no, you can't antialias an existing line because you don't truly know where the bounds of the line are--or mathematically where the line exists in relation to the surrounding pixels. Add that to the fact that the line actually obscures underlying pixels--which can't be blended into line.

You could smooth the image; but I don't believe that's even close to anti-aliasing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.