Display Document Analysis results

Question

Is it possible to print the detected blocks after the Analysis?

Answer

The following code will display the document analysis results graphically:

private void DrawBlocks(FREngine.Layout layout, string imagePath)
{
//create a Graphics object
Bitmap InitialImage = new Bitmap(imagePath);
Bitmap EditableImage = new Bitmap(InitialImage);
Graphics gr = Graphics.FromImage(EditableImage);

//draw each block
for (int i = 0; i < layout.Blocks.Count; i++)
{
//set pen color depending on block type;
int type = (int)layout.Blocks.Item(i).Type;

Color clr;
switch (type)
{
case 0:
clr = Color.Green; //text
break;
case 1:
clr = Color.Red; //raster picture
break;
case 2:
clr = Color.Purple; //table
break;
case 3:
clr = Color.LawnGreen; //barcode
break;
default:
clr = Color.Pink; //others
break;
}

Pen pen = new Pen(clr, 10);

//draw each region of the current block using selected color
for (int j = 0; j < layout.Blocks.Item(i).Region.Count; j++)
{
int left = layout.Blocks.Item(i).Region.get_Left(j);
int top = layout.Blocks.Item(i).Region.get_Top(j);
int right = layout.Blocks.Item(i).Region.get_Right(j);
int bottom = layout.Blocks.Item(i).Region.get_Bottom(j);

int width = right - left;
int height = bottom - top;

gr.DrawRectangle(pen, left, top, width, height);
}
}
//save modified image
EditableImage.Save(System.IO.Path.ChangeExtension(imagePath, ".gif"), System.Drawing.Imaging.ImageFormat.Gif);
}

private void processImage()
{
string imagePath = @"D:\Demo.tif";
FREngine.FRDocument document = engineLoader.Engine.CreateFRDocumentFromImage(imagePath);
document.Analyze(null);
DrawBlocks(document.Pages[0].Layout, imagePath);

document.Close();
}

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.