mouthpiec
mouthpiec

Reputation: 4033

Resizing a monochromatic image in C#

I have the following code to resize a monochromatic image (hence pixel value is 0[black] or 255[white]) with the following code

        Bitmap ResizedCharImage = new Bitmap(newwidth, newheight);

        using (Graphics g = Graphics.FromImage((Image)ResizedCharImage))
        {
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBilinear;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.DrawImage(CharBitmap, new Rectangle(0, 0, newwidth, newheight),
                new Rectangle(0, 0, CharBitmap.Width, CharBitmap.Height), GraphicsUnit.Pixel);
        }

The problem that I am having is that after resizing (i am enlarging the image) some of the pixel values become 254, 253, 1, 2 etc. (and so are not monochromatic.) I need that this do not occur. Is this possible, maybe by changing one of the Graphins properties?

Upvotes: 1

Views: 756

Answers (2)

mouthpiec
mouthpiec

Reputation: 4033

apparently problem solved by setting InterpolationMode to

InterpolationMode.NearestNeighbor;

Upvotes: 2

Adam Robinson
Adam Robinson

Reputation: 185643

Use SmoothingMode.None

Upvotes: 3

Related Questions