网格尺寸:160*160
行数*列数 = 16*16
我为此创建了一个位图。网格的每个单元格都填充有不同的颜色。我需要执行颜色插值。
我猜您想要执行以下操作:拍摄 16x16 像素图像并将其插值为 160x160 像素图像。以下是三个示例输出(您只说要使用样条插值,但没有说是哪一个):
- 最近邻居
- 双线性(应用线性样条插补 http://en.wikipedia.org/wiki/Spline_interpolation#Linear_spline_interpolation在 x 和 y 方向上)
- 双三次(应用三次样条插值 http://en.wikipedia.org/wiki/Spline_interpolation#Cubic_spline_interpolation在 x 和 y 方向上)
原始图片http://img695.imageshack.us/img695/8200/nearest.png http://img695.imageshack.us/img695/8200/nearest.png
线性插值img http://img707.imageshack.us/img707/3815/linear.png http://img707.imageshack.us/img707/3815/linear.png
三次插值 img http://img709.imageshack.us/img709/1985/cubic.png http://img709.imageshack.us/img709/1985/cubic.png
.net Framework 提供了这些方法以及其他一些方法(请参阅MSDN,插值模式枚举 http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.interpolationmode.aspx).
此代码将执行图像缩放。 (我写了一个扩展方法,但是你可以忽略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;
}
你可以像这样使用它:
Bitmap my16x16img = new Bitmap(16, 16);
Bitmap the160x160img = (Bitmap)my16x16img.EnlargeImage(10);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)