I'm new to programming raster graphics and trying to build a simple app, and I want to make sure lines have a smooth anti-aliased look. I am wondering if this can be achieved simply by having a brush that stamps circle gradients that look like this, where the outer color could be any color but most importantly an alpha of 0:

enter image description here

In other words, does a simple gradient satisfy the needs of anti-aliasing or is there a more complex algorithm involved?


Yes, this will work. You'll want to have the length of the gradient be short, like 0.5-1 pixels. As long as it produces a slight region of falloff around the edges of the shape, it will suffice for antialiasing.

A somewhat more efficient approach than literally stamping out zillions of brushes would be to evaluate the distance of each pixel center (in the area being drawn) to the shape being drawn, such as a line, stroke, rectangle, etc. and then applying the gradient as a function based on the distance. That's how the classic Fast Prefiltered Lines article works.

  • $\begingroup$ Thanks -- why do you suggest a short gradient of 0.5 - 1 pixels? I would think that a large gradient could be a parameterized effect/style of the brush, and as long as there is a gradient of any length that ends with an alpha off 0, it would be antialiased, is that an appropriate assumption? $\endgroup$ – johnbakers Jul 21 at 18:22
  • 1
    $\begingroup$ For antialiasing you don't want it to be too blurry - you want a sharp but smooth appearance. You can certainly do a longer gradient if you wish to have the blurry appearance, but I wouldn't call it antialiasing at that point, I'd call it blurring. $\endgroup$ – Nathan Reed Jul 21 at 18:31

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.