[英]Generate thumbnail with white border
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. 我需要从一组jpg缩略图中生成缩略图,这些缩略图需要有一个小的白色边框,以便在地图上显示时看起来像是“照片”。 Getting the thumbnails themselves is easy but I can't figure out how to get the border. 自己获取缩略图很容易,但我不知道如何获取边框。
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. 它创建一个新的Bitmap
对象,该对象的大小为原始对象的大小加上2倍的边框宽度,然后在中间绘制原始图像,然后返回完成的图像。
You can do a lot of drawing/painting with the Graphics
object above too. 您也可以使用上方的Graphics
对象进行大量绘图/绘制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.