/// <summary> /// Copies a rectangle from the bitmap to a new bitmap /// </summary> /// <param name="section">Source rectangle</param> /// <returns>Rectangle from current image as new bitmap</returns> public ManagedBitmap GetRectangle(Rectangle section) { var newRectangle = new ManagedBitmap(section.Width, section.Height); int recty = 0; for (int y = section.Top; y < section.Top + section.Height; y++) { int rectx = 0; for (int x = section.Left; x < section.Left + section.Width; x++) { newRectangle.SetPixel(rectx, recty, this.GetPixel(x, y)); rectx++; } recty++; } return(newRectangle); }
private void listBoxInspectItems_SelectedIndexChanged(object sender, EventArgs e) { labelImageInfo.Text = string.Empty; labelExpandCount.Text = string.Empty; if (listBoxInspectItems.SelectedIndex < 0) return; _selectedCompareNode = null; _selectedCompareBinaryOcrBitmap = null; pictureBoxInspectItem.Image = _imageSources[listBoxInspectItems.SelectedIndex]; pictureBoxCompareBitmap.Image = null; pictureBoxCompareBitmapDouble.Image = null; int index = (listBoxInspectItems.SelectedIndex); var match = _matches[index]; _selectedMatch = match; if (!string.IsNullOrEmpty(match.Name)) { if (_binOcrDb != null) { bool bobFound = false; foreach (BinaryOcrBitmap bob in _binOcrDb.CompareImages) { if (match.Name == bob.Key) { textBoxText.Text = bob.Text; checkBoxItalic.Checked = bob.Italic; _selectedCompareBinaryOcrBitmap = bob; var bitmap = bob.ToOldBitmap(); pictureBoxCompareBitmap.Image = bitmap; pictureBoxCompareBitmapDouble.Width = bitmap.Width * 2; pictureBoxCompareBitmapDouble.Height = bitmap.Height * 2; pictureBoxCompareBitmapDouble.Image = bitmap; var matchBob = new BinaryOcrBitmap(new NikseBitmap(_imageSources[listBoxInspectItems.SelectedIndex])); if (matchBob.Hash == bob.Hash && matchBob.Width == bob.Width && matchBob.Height == bob.Height && matchBob.NumberOfColoredPixels == bob.NumberOfColoredPixels) { buttonAddBetterMatch.Enabled = false; // exact match } else { buttonAddBetterMatch.Enabled = true; } bobFound = true; break; } } if (!bobFound) { foreach (BinaryOcrBitmap bob in _binOcrDb.CompareImagesExpanded) { if (match.Name == bob.Key) { textBoxText.Text = bob.Text; checkBoxItalic.Checked = bob.Italic; _selectedCompareBinaryOcrBitmap = bob; var bitmap = bob.ToOldBitmap(); pictureBoxCompareBitmap.Image = bitmap; pictureBoxCompareBitmapDouble.Width = bitmap.Width * 2; pictureBoxCompareBitmapDouble.Height = bitmap.Height * 2; pictureBoxCompareBitmapDouble.Image = bitmap; buttonAddBetterMatch.Enabled = false; // exact match labelExpandCount.Text = string.Format("Expand count: {0}", bob.ExpandCount); break; } } } } else { foreach (XmlNode node in ImageCompareDocument.DocumentElement.ChildNodes) { if (node.Attributes["Text"] != null && node.InnerText == match.Name) { string text = node.Attributes["Text"].InnerText; string imageFileName = node.InnerText; imageFileName = Path.Combine(_directoryPath, imageFileName); textBoxText.Text = text; checkBoxItalic.Checked = node.Attributes["Italic"] != null; string databaseName = Path.Combine(_directoryPath, "Images.db"); using (var f = new FileStream(databaseName, FileMode.Open)) { try { string name = node.InnerText; int pos = Convert.ToInt32(name); f.Position = pos; var mbmp = new ManagedBitmap(f); var bitmap = mbmp.ToOldBitmap(); pictureBoxCompareBitmap.Image = bitmap; pictureBoxCompareBitmapDouble.Width = bitmap.Width * 2; pictureBoxCompareBitmapDouble.Height = bitmap.Height * 2; pictureBoxCompareBitmapDouble.Image = bitmap; labelImageInfo.Text = string.Format(Configuration.Settings.Language.VobSubEditCharacters.Image + " - {0}x{1}", bitmap.Width, bitmap.Height); } catch (Exception exception) { labelImageInfo.Text = Configuration.Settings.Language.VobSubEditCharacters.Image; MessageBox.Show(exception.Message); } } _selectedCompareNode = node; break; } } } } buttonAddBetterMatch.Text = Configuration.Settings.Language.VobSubOcrCharacterInspect.AddBetterMatch; if (_selectedMatch.Text == Configuration.Settings.Language.VobSubOcr.NoMatch) { buttonUpdate.Enabled = false; buttonDelete.Enabled = false; buttonAddBetterMatch.Enabled = true; buttonAddBetterMatch.Text = Configuration.Settings.Language.VobSubOcrCharacterInspect.Add; textBoxText.Enabled = true; textBoxText.Text = string.Empty; checkBoxItalic.Enabled = true; } else if (_selectedCompareNode == null && _selectedCompareBinaryOcrBitmap == null) { buttonUpdate.Enabled = false; buttonDelete.Enabled = false; buttonAddBetterMatch.Enabled = false; textBoxText.Enabled = false; textBoxText.Text = string.Empty; checkBoxItalic.Enabled = false; } else { buttonUpdate.Enabled = true; buttonDelete.Enabled = true; if (_selectedCompareNode != null) buttonAddBetterMatch.Enabled = true; textBoxText.Enabled = true; checkBoxItalic.Enabled = true; } }
private void ListBoxFileNamesSelectedIndexChanged(object sender, EventArgs e) { checkBoxItalic.Checked = _italics[listBoxFileNames.SelectedIndex]; string name = listBoxFileNames.Items[listBoxFileNames.SelectedIndex].ToString(); string databaseName = _directoryPath + "Images.db"; string posAsString = GetSelectedFileName(); Bitmap bmp = null; labelExpandCount.Text = string.Empty; if (_binOcrDb != null) { var bob = GetSelectedBinOcrBitmap(); if (bob != null) { bmp = bob.ToOldBitmap(); if (bob.ExpandCount > 0) { labelExpandCount.Text = string.Format("Expand count: {0}", bob.ExpandCount); } } } else if (File.Exists(databaseName)) { using (var f = new FileStream(databaseName, FileMode.Open)) { if (name.Contains(']')) name = name.Substring(name.IndexOf(']') + 1).Trim(); f.Position = Convert.ToInt64(name); bmp = new ManagedBitmap(f).ToOldBitmap(); } } if (bmp == null) { bmp = new Bitmap(1, 1); labelImageInfo.Text = Configuration.Settings.Language.VobSubEditCharacters.ImageFileNotFound; } pictureBox1.Image = bmp; pictureBox2.Width = bmp.Width * 2; pictureBox2.Height = bmp.Height * 2; pictureBox2.Image = bmp; if (Additions != null && Additions.Count > 0) { if (_binOcrDb != null) { var bob = GetSelectedBinOcrBitmap(); foreach (var a in Additions) { if (bob != null && bob.Text != null && bob.Key == a.Name) { textBoxText.Text = a.Text; checkBoxItalic.Checked = a.Italic; break; } } } else { string target = GetSelectedFileName(); foreach (var a in Additions) { if (target.StartsWith(a.Name)) { textBoxText.Text = a.Text; break; } } } } }
/// <summary> /// Copies a rectangle from the bitmap to a new bitmap /// </summary> /// <param name="section">Source rectangle</param> /// <returns>Rectangle from current image as new bitmap</returns> public ManagedBitmap GetRectangle(Rectangle section) { var newRectangle = new ManagedBitmap(section.Width, section.Height); int recty = 0; for (int y = section.Top; y < section.Top + section.Height; y++) { int rectx = 0; for (int x = section.Left; x < section.Left + section.Width; x++) { newRectangle.SetPixel(rectx, recty, this.GetPixel(x, y)); rectx++; } recty++; } return newRectangle; }
/// <summary> /// Copies a rectangle from the bitmap to a new bitmap /// </summary> /// <param name="section">Source rectangle</param> /// <returns>Rectangle from current image as new bitmap</returns> public ManagedBitmap GetRectangle(Rectangle section) { var newRectangle = new ManagedBitmap(section.Width, section.Height); int recty = 0; for (int y = section.Top; y < section.Top + section.Height; y++) { int rectx = 0; for (int x = section.Left; x < section.Left + section.Width; x++) { Color c = Color.Transparent; if (GetPixel(x, y) > 0) c = Color.White; newRectangle.SetPixel(rectx, recty, c); rectx++; } recty++; } return newRectangle; }