I need to generate thumbnails from a set of jpg's that need to have a small white border so that they appear to be "photos" when displayed on a map. Getting the thumbnails themselves is easy but I can't figure out how to get the border.
+3
A:
Here's a quick hack:
public Image AppendBorder(Image original, int borderWidth)
{
var borderColor = Color.White;
var newSize = new Size(
original.Width + borderWidth * 2,
original.Height + borderWidth * 2);
var img = new Bitmap(newSize.Width, newSize.Height);
var g = Graphics.FromImage(img);
g.Clear(borderColor);
g.DrawImage(original, new Point(borderWidth, borderWidth));
g.Dispose();
return img;
}
It creates a new Bitmap
object which has the size of the original plus 2 times border width and then paint the original image in the middle and then return the finished image.
You can do a lot of drawing/painting with the Graphics
object above too.
chakrit
2008-09-16 16:20:12
With a little bit of error trapping on this, it is the complete solution
Mitchel Sellers
2008-09-16 21:30:02