2010-04-08 78 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;