views:

55

answers:

2

Hi,

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?

+2  A: 

Use SmoothingMode.None

Adam Robinson
+1  A: 

apparently problem solved by setting InterpolationMode to

InterpolationMode.NearestNeighbor;
mouthpiec