4

When I use this method to resize a bitmap:

    private Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
    {
        Bitmap result = new Bitmap(nWidth, nHeight);
        using (Graphics g = Graphics.FromImage((Image)result))
        {
            g.SmoothingMode = SmoothingMode.None;
            g.DrawImage(b, 0, 0, nWidth, nHeight);
        }
        return result;
    }

It still uses antialiasing even though I specified:

g.SmoothingMode = SmoothingMode.None;

I want just a basic resizing without any smoothing.

Richard Knop
  • 81,041
  • 149
  • 392
  • 552

3 Answers3

11

Instead of doing

g.SmoothingMode = SmoothingMode.None;

you should do

g.InterpolationMode = InterpolationMode.NearestNeighbor;
Michael
  • 8,920
  • 3
  • 38
  • 56
4

Anti-aliasing is a sub-pixel thing, you're actually looking for Nearest Neighbour interpolation during the resize operation.

Gareth Davidson
  • 4,857
  • 2
  • 26
  • 45
1

Take a look at the InterpolationMode property.

I think that's what you want. Hanselman has a good blog article on it.

Dave Markle
  • 95,573
  • 20
  • 147
  • 170