Phi*_*ier 12
我想您要执行以下操作:拍摄16x16像素图像并将其插值为160x160像素图像.这里有三个示例输出(您只表示要使用样条插值,但不是哪一个):
原始IMG http://img695.imageshack.us/img695/8200/nearest.png 线性插值IMG http://img707.imageshack.us/img707/3815/linear.png 三次插值IMG HTTP://img709.imageshack.我们/ img709/1985/cubic.png
.net Framework提供了这些和更多的方法(参见MSDN,InterpolationMode Enumeration).
此代码将执行图像缩放.(我写了一个扩展方法,但你可以放弃this关键字并将其用作普通函数):
public static Image EnlargeImage(this Image original, int scale)
{
Bitmap newimg = new Bitmap(original.Width * scale, original.Height * scale);
using(Graphics g = Graphics.FromImage(newimg))
{
// Here you set your interpolation mode
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
// Scale the image, by drawing it on the larger bitmap
g.DrawImage(original, new Rectangle(Point.Empty, newimg.Size));
}
return newimg;
}
Run Code Online (Sandbox Code Playgroud)
你会像这样使用它:
Bitmap my16x16img = new Bitmap(16, 16);
Bitmap the160x160img = (Bitmap)my16x16img.EnlargeImage(10);
Run Code Online (Sandbox Code Playgroud)