L
LordAsm
I've posted my question in the Visual C# session, but seems they find it was
the wrong place, so I'm trying here, if any moderator think is it misplaced,
please guide me to the right forum or just move there, please.
I'm making a forms processing application here, and I'm having problems with
MODI.Image holding the file handle open so I can't overwrite it.
For each document I'm processing, I'm saving chunks of the full images in
some files in order to OCR them separately. If I do this to one document
only, it works fine. If I process a second document, I receive a "Generic
GDI+ Error" when saving the image region to disk, and after some debugging I
found that the culprit is the MODI component, which do not release the image
after the OCR process.
Somebody have a possible solution?
I've done the following thing to release the image, but now sometimes the
error still occurs (not anymore in the 2nd page, but in the middle of the
process)... (This loop occurs for every region in the document (there is
approx. 80 regions for each document))
for (int k = 0; k < frm1ptr.pbox.Count; k++)
{
Rectangle bounds = new Rectangle();
bounds.X = tmppbox.Left;
bounds.Y = tmppbox.Top;
bounds.Width = tmppbox.Width;
bounds.Height = tmppbox.Height;
Bitmap regionimg = parseimg.Clone(bounds, PixelFormat.DontCare);
regionimg.Save(Application.StartupPath + "\\imgs\\" + tmp.nome + "_" +
tmp.indice.ToString() + ".tif", ImageFormat.Tiff);
regionimg.Dispose();
regionimg = null;
MODI.Document ocr = new MODI.Document();
ocr.OnOCRProgress += new
MODI._IDocumentEvents_OnOCRProgressEventHandler(this.ShowProgress);
ocr.Create(Application.StartupPath + "\\imgs\\" + tmp.nome + "_" +
tmp.indice.ToString() + ".tif");
MODI.Image layoutimg = null;
MODI.Layout layout;
MODI.MiDocView docv = new MODI.MiDocView();
string tmpstr = "";
try
{
layoutimg = (MODI.Image)ocr.Images[0];
layoutimg.OCR(tmp.language, false, false);
layout = layoutimg.Layout;
int counter = layout.Words.Count;
for (int j = 0; j < counter ; j++)
{
MODI.Word word = (MODI.Word)layout.Words[j];
// TODO: Procedimentos de tratamento de palavras (CEK)
tmpstr += word.Text + " "; // Identificou a palavra
}
}
catch (SystemException ex)
{
tmpstr = "";
}
ocr.Close(false);
System.Runtime.InteropServices.Marshal.ReleaseComObject(layout);
System.Runtime.InteropServices.Marshal.ReleaseComObject(layoutimg.Picture);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(layoutimg.Picture);
System.Runtime.InteropServices.Marshal.ReleaseComObject(layoutimg);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(layoutimg);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ocr);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(ocr);
layout = null;
layoutimg = null;
ocr = null;
GC.Collect();
GC.WaitForPendingFinalizers();
processedregions++;
}
the wrong place, so I'm trying here, if any moderator think is it misplaced,
please guide me to the right forum or just move there, please.
I'm making a forms processing application here, and I'm having problems with
MODI.Image holding the file handle open so I can't overwrite it.
For each document I'm processing, I'm saving chunks of the full images in
some files in order to OCR them separately. If I do this to one document
only, it works fine. If I process a second document, I receive a "Generic
GDI+ Error" when saving the image region to disk, and after some debugging I
found that the culprit is the MODI component, which do not release the image
after the OCR process.
Somebody have a possible solution?
I've done the following thing to release the image, but now sometimes the
error still occurs (not anymore in the 2nd page, but in the middle of the
process)... (This loop occurs for every region in the document (there is
approx. 80 regions for each document))
for (int k = 0; k < frm1ptr.pbox.Count; k++)
{
Rectangle bounds = new Rectangle();
bounds.X = tmppbox.Left;
bounds.Y = tmppbox.Top;
bounds.Width = tmppbox.Width;
bounds.Height = tmppbox.Height;
Bitmap regionimg = parseimg.Clone(bounds, PixelFormat.DontCare);
regionimg.Save(Application.StartupPath + "\\imgs\\" + tmp.nome + "_" +
tmp.indice.ToString() + ".tif", ImageFormat.Tiff);
regionimg.Dispose();
regionimg = null;
MODI.Document ocr = new MODI.Document();
ocr.OnOCRProgress += new
MODI._IDocumentEvents_OnOCRProgressEventHandler(this.ShowProgress);
ocr.Create(Application.StartupPath + "\\imgs\\" + tmp.nome + "_" +
tmp.indice.ToString() + ".tif");
MODI.Image layoutimg = null;
MODI.Layout layout;
MODI.MiDocView docv = new MODI.MiDocView();
string tmpstr = "";
try
{
layoutimg = (MODI.Image)ocr.Images[0];
layoutimg.OCR(tmp.language, false, false);
layout = layoutimg.Layout;
int counter = layout.Words.Count;
for (int j = 0; j < counter ; j++)
{
MODI.Word word = (MODI.Word)layout.Words[j];
// TODO: Procedimentos de tratamento de palavras (CEK)
tmpstr += word.Text + " "; // Identificou a palavra
}
}
catch (SystemException ex)
{
tmpstr = "";
}
ocr.Close(false);
System.Runtime.InteropServices.Marshal.ReleaseComObject(layout);
System.Runtime.InteropServices.Marshal.ReleaseComObject(layoutimg.Picture);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(layoutimg.Picture);
System.Runtime.InteropServices.Marshal.ReleaseComObject(layoutimg);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(layoutimg);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ocr);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(ocr);
layout = null;
layoutimg = null;
ocr = null;
GC.Collect();
GC.WaitForPendingFinalizers();
processedregions++;
}