2011-07-21 58 views
-1

我正在使用Microsoft Office Document Imaging(MODI)並試圖加載TIF 文件,但在執行OCR之前將其轉換爲灰度。使用MODI並將圖像更改爲灰度

我不知道如何做到這一點。

我有這個在我的代碼:

私人MODI.Document _MODIDocument = NULL;

_MODIDocument = new MODI.Document();

_MODIDocument.Create(filename); axMiDocView1.Document = _MODIDocument;

有人能告訴我如何將文檔的圖像部分轉換爲灰度?

Bitmap oldBitmap = new Bitmap(Server.MapPath("~/Db/Plates/" + dosyaadi), false); 
Bitmap newBitmap = Grayscale(new Bitmap(oldBitmap)); 
string name = "grayscale"; 
newBitmap.Save(Server.MapPath("~/Db/Plates/") + name + ".jpg", ImageFormat.Jpeg); 

感謝

+0

變化技術。我們走了這條路,遇到了Office的版本問題,在網絡驅動器上遇到了損壞的文件,然後MS終止了Office 2010。 – TrueWill

回答

0
public static Bitmap Grayscale(Bitmap bitmap) 
{ 
    //Declare myBitmap as a new Bitmap with the same Width & Height 
    Bitmap myBitmap = new Bitmap(bitmap.Width, bitmap.Height); 

    for (int i = 0; i < bitmap.Width; i++) 
    { 
     for (int x = 0; x < bitmap.Height; x++) 
     { 
      //Get the Pixel 
      Color BitmapColor = bitmap.GetPixel(i, x); 
      //I want to come back here at some point and understand, then change, the constants 
      //Declare grayScale as the Grayscale Pixel 
      int grayScale = (int)((BitmapColor.R * 0.3) + (BitmapColor.G * 0.59) + (BitmapColor.B * 0.11)); 

      //Declare myColor as a Grayscale Color 
      Color myColor = Color.FromArgb(grayScale, grayScale, grayScale); 

      //Set the Grayscale Pixel 
      myBitmap.SetPixel(i, x, myColor); 
     } 
    } 
    return myBitmap; 
} 

Click事件,然後刪除組織PIC ..