private static string RunOcr() { int res; TNSOCR.Img_DeleteAllBlocks(ImgObj); if (Frame.Width > 0) { Rectangle r = Frame; int w, h; TNSOCR.Img_GetSize(ImgObj, out w, out h); if (r.X < 0) { r.X = 0; } if (r.Y < 0) { r.Y = 0; } if (r.Width > w) { r.Width = w; } if (r.Height > h) { r.Height = h; } int BlkObj; res = TNSOCR.Img_AddBlock(ImgObj, r.Left, r.Top, r.Width, r.Height, out BlkObj); if (res > TNSOCR.ERROR_FIRST) { ShowError("Img_AddBlock", res); return(null); } //detect text block inversion TNSOCR.Blk_Inversion(BlkObj, TNSOCR.BLK_INVERSE_DETECT); Frame.Width = 0; } //zoning will not be executed since we have created text block res = TNSOCR.Img_OCR(ImgObj, TNSOCR.OCRSTEP_ZONING, TNSOCR.OCRSTEP_LAST, 0); if (res > TNSOCR.ERROR_FIRST) { ShowError("Img_OCR", res); return(null); } int flags = TNSOCR.FMT_EDITCOPY; //or TNSOCR.FMT_EXACTCOPY StringBuilder txt = new StringBuilder(0); int n = TNSOCR.Img_GetImgText(ImgObj, txt, 0, flags); //get buffer text length plus null-terminated zero txt = new StringBuilder(n + 1); TNSOCR.Img_GetImgText(ImgObj, txt, n + 1, flags); return(txt.ToString()); }