void AddZones(bool bUserDrawnZone) { try { if (bUserDrawnZone && (_frameRect.Width < 2 || _frameRect.Height < 2)) { return; } // Initialize the OcrZone and add it to the image. OcrZone zoneData = new OcrZone(); MyItemData itemData = (MyItemData)_cmbOcrModules.SelectedItem; OcrZoneType selectedModule = (OcrZoneType)itemData.ZoneType; switch (selectedModule) { case OcrZoneType.Text: // AUTO if (bUserDrawnZone) { zoneData.Bounds = _frameRect; zoneData.ZoneType = OcrZoneType.Text; _ocrPage.Zones.Add(zoneData); } else { _ocrPage.AutoZone(null); } break; case OcrZoneType.Micr: // MICR if (bUserDrawnZone) { zoneData.Bounds = _frameRect; } else { zoneData.Bounds = new LeadRect(38, 678, 1655, 87); } zoneData.ZoneType = OcrZoneType.Micr; _ocrPage.Zones.Add(zoneData); break; case OcrZoneType.Omr: // OMR if (bUserDrawnZone) { zoneData.Bounds = _frameRect; zoneData.ZoneType = OcrZoneType.Omr; _ocrPage.Zones.Add(zoneData); } else { _ocrPage.LoadZones(Path.Combine(ImagesFolder, "Mix_omr.ozf")); } break; case OcrZoneType.Icr: // HandPrintedCharacter if (bUserDrawnZone) { zoneData.Bounds = _frameRect; } else { zoneData.Bounds = new LeadRect(0, 0, _ocrPage.Width, _ocrPage.Height); } zoneData.ZoneType = OcrZoneType.Icr; zoneData.CharacterFilters = (OcrZoneCharacterFilters)itemData.CharacterFilters; _ocrPage.Zones.Add(zoneData); break; } } catch (Exception ex) { Messager.ShowError(this, ex); } }
private void LoadUniqueFieldValueInstanceImages() { string zoneFile, sql, imageFile = "", imagePath; int page = 0, zoneID = 1; if (ocrPageZones != null) { ocrPageZones.Dispose(); ocrPageZones = null; } if (uniqueFieldValueRowNumber >= dataTableUniqueFieldValues.Rows.Count) { return; } OcrZone zone; LeadRect zoneRect; RasterImage pageImage = null, zoneImage; textBoxValue.Text = dataTableUniqueFieldValues.Rows[uniqueFieldValueRowNumber][0].ToString(); sql = "select Page, ZoneID from Field where Batch = '" + BatchName + "' and FieldID = " + fieldIndex.ToString() + " and (ValueAdvantage = '" + textBoxValue.Text.Replace("'", "''") + "') order by Page, Line"; oleDbCommand = new OleDbCommand(sql, oleDbConnection); oleDbDataAdapter = new OleDbDataAdapter(oleDbCommand); dataTableUniqueFieldValueInstances = new DataTable(); oleDbDataAdapter.Fill(dataTableUniqueFieldValueInstances); images = new List <RasterImage>(); foreach (DataRow instanceRow in dataTableUniqueFieldValueInstances.Rows) { zoneID = int.Parse(instanceRow["ZoneID"].ToString()); if (page != int.Parse(instanceRow[0].ToString())) { page = int.Parse(instanceRow[0].ToString()); sql = "select top 1 Srcfile from " + BatchTableName + " where Batch = '" + BatchName + "' and Page = " + page.ToString(); oleDbCommand = new OleDbCommand(sql, oleDbConnection); oleDbDataAdapter = new OleDbDataAdapter(oleDbCommand); DataTable dataTableSrcfile = new System.Data.DataTable(); oleDbDataAdapter.Fill(dataTableSrcfile); if (dataTableSrcfile.Rows.Count > 0) { imageFile = dataTableSrcfile.Rows[0][0].ToString(); imagePath = @"I:\" + BatchName.Split(' ')[0] + @"\" + imageFile; if (imageFile.Split('\\').Length == 3) { imageFile = imageFile.Split('\\')[2]; } else { imageFile = imageFile.Split('\\')[1]; } zoneFile = imagePath.Substring(0, imagePath.LastIndexOf(".")) + ".ozf"; if (File.Exists(zoneFile)) { try { pageImage = codecs.Load(imagePath); if (pageImage.XResolution < 150) { pageImage.XResolution = 150; } if (pageImage.YResolution < 150) { pageImage.YResolution = 150; } ocrPageZones = OcrEngine.CreatePage(pageImage, OcrImageSharingMode.AutoDispose); ocrPageZones.LoadZones(zoneFile); } catch (Exception ex) { if (showedMemoryMessage == false) { Messager.ShowInformation(this, "Could not open " + imagePath + ". " + ex.Message); showedMemoryMessage = true; } pageImage = null; } } } } if (pageImage != null) { zone = GetPageZone(ocrPageZones, zoneID); zoneRect = zone.Bounds.ToRectangle(150, 150); zoneImage = pageImage.Clone(zoneRect); zoneImage.CustomData.Add("Page", page.ToString()); zoneImage.CustomData.Add("ZoneID", instanceRow["ZoneID"].ToString()); zoneImage.CustomData.Add("FieldID", fieldIndex.ToString()); images.Add(zoneImage); } if (images.Count > 59) { break; } } DisplayUniqueFieldValueInstanceImagePage(); }