mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
"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
This commit is contained in:
parent
6f38ad9d65
commit
2bf05580cf
14
src/Forms/VobSubOcr.Designer.cs
generated
14
src/Forms/VobSubOcr.Designer.cs
generated
@ -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
|
||||
|
@ -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];
|
||||
//<Event InTC="00:00:24:07" OutTC="00:00:31:13" Forced="False">
|
||||
// <Graphic Width="696" Height="111" X="612" Y="930">subtitle_exp_0001.png</Graphic>
|
||||
//</Event>
|
||||
sb.AppendLine("<Event InTC=\"" + BdnXmlTimeCode(p.StartTime) + "\" OutTC=\"" + BdnXmlTimeCode(p.EndTime) + "\" Forced=\"False\">");
|
||||
int x = (width - bmp.Width) / 2;
|
||||
int y = height - (bmp.Height + border);
|
||||
sb.AppendLine(" <Graphic Width=\"" + bmp.Width.ToString() + "\" Height=\"" + bmp.Height.ToString() + "\" X=\"" + x.ToString() + "\" Y=\"" + y.ToString() + "\">" + numberString + ".png</Graphic>");
|
||||
sb.AppendLine("</Event>");
|
||||
|
||||
bmp.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
XmlDocument doc = new XmlDocument();
|
||||
Paragraph first = _subtitle.Paragraphs[0];
|
||||
Paragraph last = _subtitle.Paragraphs[_subtitle.Paragraphs.Count - 1];
|
||||
doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine +
|
||||
"<BDN Version=\"0.93\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"BD-03-006-0093b BDN File Format.xsd\">" + Environment.NewLine +
|
||||
"<Description>" + Environment.NewLine +
|
||||
"<Name Title=\"subtitle_exp\" Content=\"\"/>" + Environment.NewLine +
|
||||
"<Language Code=\"eng\"/>" + Environment.NewLine +
|
||||
"<Format VideoFormat=\"1080p\" FrameRate=\"25\" DropFrame=\"False\"/>" + Environment.NewLine +
|
||||
"<Events Type=\"Graphic\" FirstEventInTC=\"" + BdnXmlTimeCode(first.StartTime) + "\" LastEventOutTC=\"" + BdnXmlTimeCode(last.EndTime) + "\" NumberofEvents=\"" + imagesSavedCount.ToString() + "\"/>" + Environment.NewLine +
|
||||
"</Description>" + Environment.NewLine +
|
||||
"<Events>" + Environment.NewLine +
|
||||
"</Events>" + Environment.NewLine +
|
||||
"</BDN>");
|
||||
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)
|
||||
|
@ -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}",
|
||||
|
Loading…
Reference in New Issue
Block a user