简体   繁体   中英

bitmap interpolation c#

Grid size : 160*160 No of row* columns = 16*16

I have created a bitmap for this. Each cell of the grid is filled with different colors. I need to perform color interpolation.

I guess you want to do the following: Take a 16x16 pixel image and interpolate it to a 160x160 pixel image. Here are three sample outputs (you only said you want to use spline interpolation, but not which one):

  1. Nearest neighbour
  2. Bilinear (Applying linear spline interpolation in both x and y direction)
  3. Bicubic (Applying cubic spline interpolation in both x and y direction)

original img http://img695.imageshack.us/img695/8200/nearest.png linear interpolation img http://img707.imageshack.us/img707/3815/linear.png cubic interpolation img http://img709.imageshack.us/img709/1985/cubic.png

The .net Framework provides those and a few more methods (see MSDN, InterpolationMode Enumeration ).

This code will perform an image scaling. (I wrote an extension method, but you can leave away the this keyword and use it as a normal function):

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;
}

You would use it like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM