Merge pull request #1443 from xylographe/xfix3

Minor fix (Forms/VobSubOcr)
This commit is contained in:
Nikolaj Olsson 2015-12-11 16:01:18 +01:00
commit 2bad89bfde

View File

@ -7524,34 +7524,35 @@ namespace Nikse.SubtitleEdit.Forms
progressBar1.Value = 0; progressBar1.Value = 0;
progressBar1.Visible = true; progressBar1.Visible = true;
int imagesSavedCount = 0; int imagesSavedCount = 0;
StringBuilder sb = new StringBuilder(); var sb = new StringBuilder();
sb.AppendLine("<html>"); sb.AppendLine("<html>");
sb.AppendLine("<head><title>Subtitle images</title></head>"); sb.AppendLine("<head><title>Subtitle images</title></head>");
sb.AppendLine("<body>"); sb.AppendLine("<body>");
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < _subtitle.Paragraphs.Count; i++)
{ {
progressBar1.Value = i; progressBar1.Value = i;
Bitmap bmp = GetSubtitleBitmap(i); var bmp = GetSubtitleBitmap(i);
string numberString = string.Format("{0:0000}", i + 1);
if (bmp != null) if (bmp != null)
{ {
string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + ".png"); var fileName = string.Format(CultureInfo.InvariantCulture, "{0:0000}.png", i + 1);
bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); var filePath = Path.Combine(folderBrowserDialog1.SelectedPath, fileName);
bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
imagesSavedCount++; imagesSavedCount++;
Paragraph p = _subtitle.Paragraphs[i]; var p = _subtitle.Paragraphs[i];
string text = string.Empty; sb.AppendFormat(CultureInfo.InvariantCulture, "#{3}:{0}->{1}<div style='text-align:center'><img src='{2}' />", p.StartTime.ToShortString(), p.EndTime.ToShortString(), fileName, i + 1);
if (!string.IsNullOrEmpty(p.Text)) if (!string.IsNullOrEmpty(p.Text))
{ {
string backgroundColor = System.Drawing.ColorTranslator.ToHtml(subtitleListView1.GetBackgroundColor(i)); var backgroundColor = System.Drawing.ColorTranslator.ToHtml(subtitleListView1.GetBackgroundColor(i));
text = "<br /><div style='font-size:22px; background-color:" + backgroundColor + "'>" + WebUtility.HtmlEncode(p.Text.Replace("<i>", "@1__").Replace("</i>", "@2__")).Replace("@1__", "<i>").Replace("@2__", "</i>").Replace(Environment.NewLine, "<br />") + "</div>"; var text = WebUtility.HtmlEncode(p.Text.Replace("<i>", "@1__").Replace("</i>", "@2__")).Replace("@1__", "<i>").Replace("@2__", "</i>").Replace(Environment.NewLine, "<br />");
sb.Append("<br /><div style='font-size:22px; background-color:").Append(backgroundColor).Append("'>").Append(text).Append("</div>");
} }
sb.AppendLine(string.Format("#{3}:{0}->{1}<div style='text-align:center'><img src='{2}.png' />" + text + "</div><br /><hr />", p.StartTime.ToShortString(), p.EndTime.ToShortString(), numberString, i + 1)); sb.AppendLine("</div><br /><hr />");
bmp.Dispose(); bmp.Dispose();
} }
} }
sb.AppendLine("</body>"); sb.AppendLine("</body>");
sb.AppendLine("</html>"); sb.AppendLine("</html>");
string htmlFileName = Path.Combine(folderBrowserDialog1.SelectedPath, "index.html"); var htmlFileName = Path.Combine(folderBrowserDialog1.SelectedPath, "index.html");
File.WriteAllText(htmlFileName, sb.ToString()); File.WriteAllText(htmlFileName, sb.ToString());
progressBar1.Visible = false; progressBar1.Visible = false;
MessageBox.Show(string.Format("{0} images saved in {1}", imagesSavedCount, folderBrowserDialog1.SelectedPath)); MessageBox.Show(string.Format("{0} images saved in {1}", imagesSavedCount, folderBrowserDialog1.SelectedPath));