【问题标题】:Using MODI and changing image to grayscale使用 MODI 并将图像更改为灰度
【发布时间】:2011-07-21 20:59:28
【问题描述】:

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

我不确定如何执行此操作。

我的代码中有这个:

私有 MODI.Document _MODIDocument = null;

_MODIDocument = new MODI.Document();

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

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

谢谢

【问题讨论】:

  • 改变技术。我们走了这条路,遇到了 Office 的版本问题,在网络驱动器上遇到了损坏的文件,然后 MS 在 Office 2010 中停止了它。

标签: c# image ocr modi


【解决方案1】:
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);

然后删除组织图片..

【讨论】:

    猜你喜欢
    • 2021-10-19
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    相关资源
    最近更新 更多