From 2bf05580cf6a368f45be7eb5389bebb6bcea340e Mon Sep 17 00:00:00 2001 From: niksedk Date: Thu, 13 Jan 2011 08:24:37 +0000 Subject: [PATCH] "Save all images" in OCR window now includes a Sony BDN XML file (for easy import in other programs) git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@243 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Forms/VobSubOcr.Designer.cs | 14 +++++----- src/Forms/VobSubOcr.cs | 46 ++++++++++++++++++++++++++++++--- src/Logic/Language.cs | 2 +- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/Forms/VobSubOcr.Designer.cs b/src/Forms/VobSubOcr.Designer.cs index edcc9c192..9a856bb19 100644 --- a/src/Forms/VobSubOcr.Designer.cs +++ b/src/Forms/VobSubOcr.Designer.cs @@ -135,40 +135,40 @@ namespace Nikse.SubtitleEdit.Forms this.saveImageAsToolStripMenuItem, this.saveAllImagesToolStripMenuItem}); this.contextMenuStripListview.Name = "contextMenuStripListview"; - this.contextMenuStripListview.Size = new System.Drawing.Size(164, 120); + this.contextMenuStripListview.Size = new System.Drawing.Size(244, 120); this.contextMenuStripListview.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripListviewOpening); // // normalToolStripMenuItem // this.normalToolStripMenuItem.Name = "normalToolStripMenuItem"; - this.normalToolStripMenuItem.Size = new System.Drawing.Size(157, 22); + this.normalToolStripMenuItem.Size = new System.Drawing.Size(243, 22); this.normalToolStripMenuItem.Text = "Normal"; this.normalToolStripMenuItem.Click += new System.EventHandler(this.NormalToolStripMenuItemClick); // // italicToolStripMenuItem // this.italicToolStripMenuItem.Name = "italicToolStripMenuItem"; - this.italicToolStripMenuItem.Size = new System.Drawing.Size(157, 22); + this.italicToolStripMenuItem.Size = new System.Drawing.Size(243, 22); this.italicToolStripMenuItem.Text = "Italic"; this.italicToolStripMenuItem.Click += new System.EventHandler(this.ItalicToolStripMenuItemClick); // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(154, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(240, 6); // // saveImageAsToolStripMenuItem // this.saveImageAsToolStripMenuItem.Name = "saveImageAsToolStripMenuItem"; - this.saveImageAsToolStripMenuItem.Size = new System.Drawing.Size(157, 22); + this.saveImageAsToolStripMenuItem.Size = new System.Drawing.Size(243, 22); this.saveImageAsToolStripMenuItem.Text = "Save image as..."; this.saveImageAsToolStripMenuItem.Click += new System.EventHandler(this.SaveImageAsToolStripMenuItemClick); // // saveAllImagesToolStripMenuItem // this.saveAllImagesToolStripMenuItem.Name = "saveAllImagesToolStripMenuItem"; - this.saveAllImagesToolStripMenuItem.Size = new System.Drawing.Size(163, 22); - this.saveAllImagesToolStripMenuItem.Text = "Save all images..."; + this.saveAllImagesToolStripMenuItem.Size = new System.Drawing.Size(243, 22); + this.saveAllImagesToolStripMenuItem.Text = "Save all images (png/bdn xml)..."; this.saveAllImagesToolStripMenuItem.Click += new System.EventHandler(this.saveAllImagesToolStripMenuItem_Click); // // labelSubtitleText diff --git a/src/Forms/VobSubOcr.cs b/src/Forms/VobSubOcr.cs index 03063d4a6..a392b3469 100644 --- a/src/Forms/VobSubOcr.cs +++ b/src/Forms/VobSubOcr.cs @@ -1779,25 +1779,65 @@ namespace Nikse.SubtitleEdit.Forms private void saveAllImagesToolStripMenuItem_Click(object sender, EventArgs e) { - int imagesSavedCount = 0; if (folderBrowserDialog1.ShowDialog(this) == DialogResult.OK) { + const int height = 1080; + const int width = 1920; + const int border = 25; + int imagesSavedCount = 0; + StringBuilder sb = new StringBuilder(); for (int i = 0; i < _subtitle.Paragraphs.Count; i++) { Bitmap bmp = GetSubtitleBitmap(i); + string numberString = string.Format("{0:0000}", i + 1); if (bmp != null) { - string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, i.ToString() + ".png"); + + string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + ".png"); bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); imagesSavedCount++; + + Paragraph p = _subtitle.Paragraphs[i]; + // + // subtitle_exp_0001.png + // + sb.AppendLine(""); + int x = (width - bmp.Width) / 2; + int y = height - (bmp.Height + border); + sb.AppendLine(" " + numberString + ".png"); + sb.AppendLine(""); + bmp.Dispose(); } - } + XmlDocument doc = new XmlDocument(); + Paragraph first = _subtitle.Paragraphs[0]; + Paragraph last = _subtitle.Paragraphs[_subtitle.Paragraphs.Count - 1]; + doc.LoadXml("" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + ""); + XmlNode events = doc.DocumentElement.SelectSingleNode("Events"); + events.InnerXml = sb.ToString(); + + File.WriteAllText(Path.Combine(folderBrowserDialog1.SelectedPath, "BDN_Index.xml"), doc.OuterXml); MessageBox.Show(string.Format("{0} images saved in {1}", imagesSavedCount, folderBrowserDialog1.SelectedPath)); } } + private static string BdnXmlTimeCode(TimeCode timecode) + { + int frames = timecode.Milliseconds / 40; // 40==25fps (1000/25) + return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", timecode.Hours, timecode.Minutes, timecode.Seconds, frames); + } + private void NormalToolStripMenuItemClick(object sender, EventArgs e) { if (_subtitle.Paragraphs.Count > 0 && subtitleListView1.SelectedItems.Count > 0) diff --git a/src/Logic/Language.cs b/src/Logic/Language.cs index c2a84c255..993fba59b 100644 --- a/src/Logic/Language.cs +++ b/src/Logic/Language.cs @@ -1276,7 +1276,7 @@ can edit in same subtitle file (collaboration)", OcrViaTesseract = "OCR via Tesseract", FixOcrErrors = "Fix OCR errors", SaveSubtitleImageAs = "Save subtitle image as...", - SaveAllSubtitleImagesAs = "Save all subtitle images as...", + SaveAllSubtitleImagesAs = "Save all images (png/bdn xml)...", XImagesSavedInY = "{0} images saved in {1}", TryModiForUnknownWords = "Try MS MODI OCR for unknown words", DictionaryX = "Dictionary: {0}",