-1

I'm using Microsoft Office Document Imaging (MODI) and am trying to load a TIF file, but convert it to grayscale before performing the OCR.

I'm not sure on how to do this.

I have this in my code:

private MODI.Document _MODIDocument = null;

_MODIDocument = new MODI.Document();

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

Can someone tell me how to convert the image portion of the document to grayscale?

Thanks

eljainc
  • 117
  • 2
  • 6
  • 12
  • Change technologies. We went that route, ran into version issues with Office, encountered corrupt files on network drives, and then MS discontinued it with Office 2010. – TrueWill Jul 21 '11 at 21:04

1 Answers1

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 event under

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

then delete org pic..

Styxxy
  • 7,462
  • 3
  • 40
  • 45
Erdogan
  • 952
  • 12
  • 26