6

I have a gray scale image that I would like to enlarge so that I can better see the individual pixels. I've tried setting Smoothing mode to none and some different Interpolation Modes (as suggested on other questions on here), but the images still appear to me as if they are still doing some sort of blending before being displayed on the screen.

basically If I have a image that is

(White, White,
 White, Black)

I want when I enlarge it to say 6x6, it to look like

 (White, White, White, White, White, White
  White, White, White, White, White, White
  White, White, White, White, White, White
  White, White, White, Black, Black, Black
  White, White, White, Black, Black, Black
  White, White, White, Black, Black, Black)

With no fading between the black and white areas, should look like a square. The image should look more "pixelized" rather then "Blurry"

1
  • What are your source and destination resolutions? Commented Jul 12, 2012 at 16:34

3 Answers 3

11

Try to set interpolation mode:

g.InterpolationMode = InterpolationMode.NearestNeighbor;
Sign up to request clarification or add additional context in comments.

3 Comments

This seems close but not quite right. Starting with a 2x2 pixel square, I do end up with four different regions but they don't all appear to be the same size.
Figured it out I needed to also add: g3.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
@hrh you're so great!
8

I too was looking to do something similar. When I found this question neither answer were quite what I was looking for but combined they were. This is what got me to where I wanted to be and from what I can tell from your question what you want.

private Bitmap ResizeBitmap(Bitmap sourceBMP, int width, int height)
{
    Bitmap result = new Bitmap(width, height);
    using (Graphics g = Graphics.FromImage(result))
    {
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
        g.DrawImage(sourceBMP, 0, 0, width, height);
    }
    return result;
}

2 Comments

A little explanation of your code should help the author understand quickly.
Thank you so much for this. Spent a couple hours trying to figure it out, trying to convert bmp to graphics and back to bmp in order to leverage the InterpolationMode, but your method made it work for it with absolutely no compression! Thank you!!
2

May be this could help!

http://www.codeproject.com/Articles/191424/Resizing-an-Image-On-The-Fly-using-NET

Else can you please implement this method and see whether it works for you?

private static Bitmap ResizeBitmap(Bitmap sourceBMP, int width, int height )
{
            Bitmap result = new Bitmap(width, height);
            using (Graphics g = Graphics.FromImage(result))
                g.DrawImage(sourceBMP, 0, 0, width, height);
            return result;
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.