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?

7
  • 1
    You may be looking for a Convolution - by far the easiest way to implement anti-aliasing. Commented Sep 22, 2014 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? Commented Sep 22, 2014 at 17:50
  • Whatever applies best to your problem space - try here for some more general ideas. Commented Sep 22, 2014 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 Commented Sep 23, 2014 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... Commented Sep 25, 2014 at 4:49

1 Answer 1

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.