public void TestMethodBinOcrSaveLoadTestExceptions() { string tempFileName = Path.GetTempFileName(); var db = new BinaryOcrDb(tempFileName); var nbmp = new NikseBitmap(2, 2); nbmp.SetPixel(0, 0, Color.Transparent); nbmp.SetPixel(1, 0, Color.Transparent); nbmp.SetPixel(1, 0, Color.Transparent); nbmp.SetPixel(1, 1, Color.White); var bob = new BinaryOcrBitmap(nbmp); bob.Text = "S"; db.Add(bob); nbmp.SetPixel(0, 0, Color.White); var bob2 = new BinaryOcrBitmap(nbmp); bob2.X = 2; bob2.Y = 4; bob2.Text = null; bob2.Italic = true; bob2.ExpandCount = 3; bob2.ExpandedList = new System.Collections.Generic.List <BinaryOcrBitmap>(); bob2.ExpandedList.Add(bob2); try { db.Add(bob2); } catch { return; } Assert.Fail(); try { File.Delete(tempFileName); } catch { } }
private void buttonAddBetterMatch_Click(object sender, EventArgs e) { if (listBoxInspectItems.SelectedIndex < 0) { return; } if (listBoxInspectItems.Items[listBoxInspectItems.SelectedIndex].ToString() == textBoxText.Text) { textBoxText.SelectAll(); textBoxText.Focus(); return; } if (_selectedCompareNode != null) { XmlNode newNode = ImageCompareDocument.CreateElement("Item"); XmlAttribute text = newNode.OwnerDocument.CreateAttribute("Text"); text.InnerText = textBoxText.Text; newNode.Attributes.Append(text); string databaseName = Path.Combine(_directoryPath, "Images.db"); FileStream f; long pos = 0; if (!File.Exists(databaseName)) { using (f = new FileStream(databaseName, FileMode.Create)) { pos = f.Position; new ManagedBitmap(pictureBoxInspectItem.Image as Bitmap).AppendToStream(f); } } else { using (f = new FileStream(databaseName, FileMode.Append)) { pos = f.Position; new ManagedBitmap(pictureBoxInspectItem.Image as Bitmap).AppendToStream(f); } } string name = pos.ToString(CultureInfo.InvariantCulture); newNode.InnerText = name; SetItalic(newNode); ImageCompareDocument.DocumentElement.AppendChild(newNode); int index = listBoxInspectItems.SelectedIndex; _matches[index].Name = name; _matches[index].ExpandCount = 0; _matches[index].Italic = checkBoxItalic.Checked; _matches[index].Text = textBoxText.Text; listBoxInspectItems.Items.Clear(); for (int i = 0; i < _matches.Count; i++) { listBoxInspectItems.Items.Add(_matches[i].Text); } listBoxInspectItems.SelectedIndex = index; ShowCount(); listBoxInspectItems_SelectedIndexChanged(null, null); } else if (_selectedCompareBinaryOcrBitmap != null) { var nbmp = new NikseBitmap((pictureBoxInspectItem.Image as Bitmap)); int x = 0; int y = 0; if (_selectedMatch != null && _selectedMatch.ImageSplitterItem != null) { x = _selectedMatch.X; y = _selectedMatch.Y; } var bob = new BinaryOcrBitmap(nbmp, checkBoxItalic.Checked, 0, textBoxText.Text, x, y); _binOcrDb.Add(bob); int index = listBoxInspectItems.SelectedIndex; _matches[index].Name = bob.Key; _matches[index].ExpandCount = 0; _matches[index].Italic = checkBoxItalic.Checked; _matches[index].Text = textBoxText.Text; listBoxInspectItems.Items.Clear(); for (int i = 0; i < _matches.Count; i++) { listBoxInspectItems.Items.Add(_matches[i].Text); } listBoxInspectItems.SelectedIndex = index; listBoxInspectItems_SelectedIndexChanged(null, null); ShowCount(); } }
private void buttonAddBetterMatch_Click(object sender, EventArgs e) { if (listBoxInspectItems.SelectedIndex < 0) { return; } if (listBoxInspectItems.Items[listBoxInspectItems.SelectedIndex].ToString() == textBoxText.Text) { textBoxText.SelectAll(); textBoxText.Focus(); return; } if (_selectedCompareBinaryOcrBitmap != null || (_binOcrDb != null && (_selectedMatch.Text == Configuration.Settings.Language.VobSubOcr.NoMatch || _selectedMatch.NOcrCharacter == null))) { var nbmp = new NikseBitmap((pictureBoxInspectItem.Image as Bitmap)); int x = 0; int y = 0; if (_selectedMatch != null && _selectedMatch.ImageSplitterItem != null) { if (_selectedMatch.ImageSplitterItem != null) { x = _selectedMatch.ImageSplitterItem.X; y = _selectedMatch.ImageSplitterItem.Top; } else { x = _selectedMatch.X; y = _selectedMatch.Y; } } var bob = new BinaryOcrBitmap(nbmp, checkBoxItalic.Checked, 0, textBoxText.Text, x, y); _binOcrDb.Add(bob); int index = listBoxInspectItems.SelectedIndex; _matches[index].Name = bob.Key; _matches[index].ExpandCount = 0; _matches[index].Italic = checkBoxItalic.Checked; _matches[index].Text = textBoxText.Text; listBoxInspectItems.Items.Clear(); for (int i = 0; i < _matches.Count; i++) { listBoxInspectItems.Items.Add(_matches[i].Text); } listBoxInspectItems.SelectedIndex = index; listBoxInspectItems_SelectedIndexChanged(null, null); ShowCount(); // update other letters that are exact matches for (int i = 0; i < _matches.Count; i++) { if (i != index && i < _imageSources.Count && _matches[i].ExpandCount == 0) { var newMatch = _binOcrDb.FindExactMatch(new BinaryOcrBitmap(new NikseBitmap(_imageSources[i]))); if (newMatch >= 0 && _binOcrDb.CompareImages[newMatch].Hash == bob.Hash) { _matches[i].Name = bob.Key; _matches[i].ExpandCount = 0; _matches[i].Italic = checkBoxItalic.Checked; _matches[i].Text = textBoxText.Text; listBoxInspectItems.Items[i] = textBoxText.Text; } } } return; } if (_selectedCompareNode != null) { XmlNode newNode = ImageCompareDocument.CreateElement("Item"); var text = newNode.OwnerDocument.CreateAttribute("Text"); text.InnerText = textBoxText.Text; newNode.Attributes.Append(text); string databaseName = Path.Combine(_directoryPath, "Images.db"); FileStream f; long pos; if (!File.Exists(databaseName)) { using (f = new FileStream(databaseName, FileMode.Create)) { pos = f.Position; new ManagedBitmap(pictureBoxInspectItem.Image as Bitmap).AppendToStream(f); } } else { using (f = new FileStream(databaseName, FileMode.Append)) { pos = f.Position; new ManagedBitmap(pictureBoxInspectItem.Image as Bitmap).AppendToStream(f); } } string name = pos.ToString(CultureInfo.InvariantCulture); newNode.InnerText = name; SetItalic(newNode); ImageCompareDocument.DocumentElement.AppendChild(newNode); int index = listBoxInspectItems.SelectedIndex; _matches[index].Name = name; _matches[index].ExpandCount = 0; _matches[index].Italic = checkBoxItalic.Checked; _matches[index].Text = textBoxText.Text; listBoxInspectItems.Items.Clear(); for (int i = 0; i < _matches.Count; i++) { listBoxInspectItems.Items.Add(_matches[i].Text); } listBoxInspectItems.SelectedIndex = index; ShowCount(); listBoxInspectItems_SelectedIndexChanged(null, null); } }