2010-04-08 76 views
1

我有以下代码来调整单色图像(因此像素值是0 [黑色]或255 [白色])用下面的代码调整大小在C#单色图像

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

,我的问题在调整大小后(我正在放大图像),某些像素值变为254,253,1,2等等(所以不是单色的)。我需要这样做不会发生。这是可能的,也许通过改变一个Graphins属性?

回答

3

使用SmoothingMode.None

2

明显问题,通过设置InterpolationMode解决了

InterpolationMode.NearestNeighbor;