Bitmap border/stroke alogirthm? I am looking for an algorithm that adds borders to a bitmap image(very much like the photoshop stroke effect) but one that will also have antialiasing to the borders(or one that copies alpha from the original bitmap to make the border look antialiased).

If you can't answer with an algorithm a direction of creating one myself would be great.

*****Update***



The part coloured black is the original ellipse and the part coloured green is the stroke.

The stroke is basically adding a contour to the bitmap or edges.
The Euclidean Distance Transform can produce dilations and erosions with suitable parameters and filtering.

The algorithm that Photoshop uses, and the one that is best suited for stroking, is to calculate the Euclidean Distance Transform in integers and without taking the square root (i.e. calculate distance squared). This can be made extremely fast using the technique from Meijster.

To get anti-aliasing, just use the fractional part of the number after taking the square root.

For example:

if (distanceSquared &lt; radius * radius)
{
  (fill solid pixel)
}
else
{
   distance = sqrt (distanceSquared);

   if (distance &lt; radius + 1)
   {
     alpha = 1 - (distance - radius);

     (blend pixel at alpha)
   }
}


This techinque is used in my open source library:

https://github.com/vinniefalco/LayerEffects.git