-1

我正在使用 Microsoft Office Document Imaging (MODI) 并尝试加载 TIF 文件,但在执行 OCR 之前将其转换为灰度。

我不确定如何做到这一点。

我的代码中有这个:

私人 MODI.Document _MODIDocument = null;

_MODIDocument = 新 MODI.Document();

_MODIDocument.Create(文件名); axMiDocView1.Document = _MODIDocument;

有人能告诉我如何将文档的图像部分转换为灰度吗?

谢谢

4

1 回答 1

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

点击事件下

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

然后删除组织图片..

于 2012-04-11T18:08:11.683 回答