位图插值c#

网格大小:160 * 160行数*列数= 16 * 16

我为此创建了一个位图。 网格的每个单元格都填充有不同的颜色。 我需要执行颜色插值。

我想您要执行以下操作:拍摄16×16像素图像并将其插值为160×160像素图像。 这里有三个示例输出(您只表示要使用样条插值,但不是哪一个):

  1. 最近的邻居
  2. 双线性(在x和y方向上应用线性样条插值 )
  3. 双立方(在x和y方向上应用三次样条插值 )

原始的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; } 

你会像这样使用它:

 Bitmap my16x16img = new Bitmap(16, 16); Bitmap the160x160img = (Bitmap)my16x16img.EnlargeImage(10);