本文整理汇总了C#中Nikse.SubtitleEdit.Forms.VobSubOcr类的典型用法代码示例。如果您正苦于以下问题:C# VobSubOcr类的具体用法?C# VobSubOcr怎么用?C# VobSubOcr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VobSubOcr类属于Nikse.SubtitleEdit.Forms命名空间,在下文中一共展示了VobSubOcr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
internal void Initialize(Bitmap bitmap, int pixelsIsSpace, bool rightToLeft, NOcrDb nOcrDb, VobSubOcr vobSubOcr)
{
_bitmap = bitmap;
var nbmp = new NikseBitmap(bitmap);
nbmp.ReplaceNonWhiteWithTransparent();
bitmap = nbmp.GetBitmap();
_bitmap2 = bitmap;
_nocrChars = nOcrDb.OcrCharacters;
_matchList = new List<VobSubOcr.CompareMatch>();
_vobSubOcr = vobSubOcr;
int minLineHeight = 6;
_imageList = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nbmp, pixelsIsSpace, rightToLeft, Configuration.Settings.VobSubOcr.TopToBottom, minLineHeight);
// _imageList = NikseBitmapImageSplitter.SplitBitmapToLetters(nbmp, pixelsIsSpace, rightToLeft, Configuration.Settings.VobSubOcr.TopToBottom);
int index = 0;
while (index < _imageList.Count)
{
ImageSplitterItem item = _imageList[index];
if (item.NikseBitmap == null)
{
listBoxInspectItems.Items.Add(item.SpecialCharacter);
_matchList.Add(null);
}
else
{
nbmp = item.NikseBitmap;
nbmp.ReplaceNonWhiteWithTransparent();
item.Y += nbmp.CropTopTransparent(0);
nbmp.CropTransparentSidesAndBottom(0, true);
nbmp.ReplaceTransparentWith(Color.Black);
//get nocr matches
Nikse.SubtitleEdit.Forms.VobSubOcr.CompareMatch match = vobSubOcr.GetNOcrCompareMatchNew(item, nbmp, nOcrDb, false, false);
if (match == null)
{
listBoxInspectItems.Items.Add("?");
_matchList.Add(null);
}
else
{
listBoxInspectItems.Items.Add(match.Text);
_matchList.Add(match);
}
}
index++;
}
}
示例2: Initialize
internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink, VobSubOcr.CompareMatch bestGuess, List<VobSubOcr.ImageCompareAddition> additions, VobSubOcr vobSubForm)
{
NikseBitmap nbmp = new NikseBitmap(vobSubImage);
nbmp.ReplaceTransparentWith(Color.Black);
vobSubImage = nbmp.GetBitmap();
radioButtonHot.Checked = true;
ShrinkSelection = false;
ExpandSelection = false;
textBoxCharacters.Text = string.Empty;
_vobSubForm = vobSubForm;
_additions = additions;
_nocrChar = new NOcrChar();
_nocrChar.MarginTop = character.Y - character.ParentY;
_imageWidth = character.NikseBitmap.Width;
_imageHeight = character.NikseBitmap.Height;
_drawLineOn = false;
_warningNoNotForegroundLinesShown = false;
buttonShrinkSelection.Visible = showShrink;
if (position.X != -1 && position.Y != -1)
{
StartPosition = FormStartPosition.Manual;
Left = position.X;
Top = position.Y;
}
pictureBoxSubtitleImage.Image = vobSubImage;
pictureBoxCharacter.Image = character.NikseBitmap.GetBitmap();
Bitmap org = (Bitmap)vobSubImage.Clone();
Bitmap bm = new Bitmap(org.Width, org.Height);
Graphics g = Graphics.FromImage(bm);
g.DrawImage(org, 0, 0, org.Width, org.Height);
g.DrawRectangle(Pens.Red, character.X, character.Y, character.NikseBitmap.Width, character.NikseBitmap.Height - 1);
g.Dispose();
pictureBoxSubtitleImage.Image = bm;
pictureBoxCharacter.Top = labelCharacters.Top + 16;
SizePictureBox();
checkBoxItalic.Checked = italicChecked;
_history = new List<NOcrChar>();
_historyIndex = -1;
}
示例3: InitializeFromVobSubOcr
/// <summary>
/// The initialize from vob sub ocr.
/// </summary>
/// <param name="subtitle">
/// The subtitle.
/// </param>
/// <param name="format">
/// The format.
/// </param>
/// <param name="exportType">
/// The export type.
/// </param>
/// <param name="fileName">
/// The file name.
/// </param>
/// <param name="vobSubOcr">
/// The vob sub ocr.
/// </param>
/// <param name="languageString">
/// The language string.
/// </param>
internal void InitializeFromVobSubOcr(Subtitle subtitle, SubtitleFormat format, string exportType, string fileName, VobSubOcr vobSubOcr, string languageString)
{
this._vobSubOcr = vobSubOcr;
this.Initialize(subtitle, format, exportType, fileName, null, this._videoFileName);
// set language
if (!string.IsNullOrEmpty(languageString))
{
if (languageString.Contains('(') && languageString[0] != '(')
{
languageString = languageString.Substring(0, languageString.IndexOf('(') - 1).Trim();
}
for (int i = 0; i < this.comboBoxLanguage.Items.Count; i++)
{
string l = this.comboBoxLanguage.Items[i].ToString();
if (l == languageString && i < this.comboBoxLanguage.Items.Count)
{
this.comboBoxLanguage.SelectedIndex = i;
}
}
}
// Disable options not available when exporting existing images
this.comboBoxSubtitleFont.Enabled = false;
this.comboBoxSubtitleFontSize.Enabled = false;
this.buttonColor.Visible = false;
this.panelColor.Visible = false;
this.checkBoxBold.Visible = false;
this.checkBoxSimpleRender.Visible = false;
this.comboBox3D.Enabled = false;
this.numericUpDownDepth3D.Enabled = false;
this.buttonBorderColor.Visible = false;
this.panelBorderColor.Visible = false;
this.labelBorderWidth.Visible = false;
this.comboBoxBorderWidth.Visible = false;
this.buttonShadowColor.Visible = false;
this.panelShadowColor.Visible = false;
this.labelShadowWidth.Visible = false;
this.comboBoxShadowWidth.Visible = false;
this.labelShadowTransparency.Visible = false;
this.numericUpDownShadowTransparency.Visible = false;
this.labelLineHeight.Visible = false;
this.numericUpDownLineSpacing.Visible = false;
}
示例4: LoadDvbFromMatroska
private bool LoadDvbFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, bool batchMode)
{
ShowStatus(_language.ParsingMatroskaFile);
Refresh();
Cursor.Current = Cursors.WaitCursor;
var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
Cursor.Current = Cursors.Default;
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
if (!batchMode)
ResetSubtitle();
_subtitle.Paragraphs.Clear();
var subtitleImages = new List<DvbSubPes>();
var subtitle = new Subtitle();
Utilities.LoadMatroskaTextSubtitle(matroskaSubtitleInfo, matroska, sub, _subtitle);
for (int index = 0; index < sub.Count; index++)
{
try
{
var msub = sub[index];
DvbSubPes pes = null;
if (msub.Data.Length > 9 && msub.Data[0] == 15 && msub.Data[1] >= SubtitleSegment.PageCompositionSegment && msub.Data[1] <= SubtitleSegment.DisplayDefinitionSegment) // sync byte + segment id
{
var buffer = new byte[msub.Data.Length + 3];
Buffer.BlockCopy(msub.Data, 0, buffer, 2, msub.Data.Length);
buffer[0] = 32;
buffer[1] = 0;
buffer[buffer.Length - 1] = 255;
pes = new DvbSubPes(0, buffer);
}
else if (VobSubParser.IsMpeg2PackHeader(msub.Data))
{
pes = new DvbSubPes(msub.Data, Mpeg2Header.Length);
}
else if (VobSubParser.IsPrivateStream1(msub.Data, 0))
{
pes = new DvbSubPes(msub.Data, 0);
}
else if (msub.Data.Length > 9 && msub.Data[0] == 32 && msub.Data[1] == 0 && msub.Data[2] == 14 && msub.Data[3] == 16)
{
pes = new DvbSubPes(0, msub.Data);
}
if (pes == null && subtitle.Paragraphs.Count > 0)
{
var last = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1];
if (last.Duration.TotalMilliseconds < 100)
{
last.EndTime.TotalMilliseconds = msub.Start;
if (last.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
{
last.EndTime.TotalMilliseconds = last.StartTime.TotalMilliseconds + 3000;
}
}
}
if (pes != null && pes.PageCompositions != null && pes.PageCompositions.Any(p => p.Regions.Count > 0))
{
subtitleImages.Add(pes);
subtitle.Paragraphs.Add(new Paragraph(string.Empty, msub.Start, msub.End));
}
}
catch
{
// continue
}
}
if (subtitleImages.Count == 0)
{
return false;
}
for (int index = 0; index < subtitle.Paragraphs.Count; index++)
{
var p = subtitle.Paragraphs[index];
if (p.Duration.TotalMilliseconds < 200)
{
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + 3000;
}
var next = subtitle.GetParagraphOrDefault(index + 1);
if (next != null && next.StartTime.TotalMilliseconds < p.EndTime.TotalMilliseconds)
{
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
}
using (var formSubOcr = new VobSubOcr())
{
formSubOcr.Initialize(subtitle, subtitleImages, Configuration.Settings.VobSubOcr, null); // TODO: language???
if (_loading)
{
formSubOcr.Icon = (Icon)Icon.Clone();
formSubOcr.ShowInTaskbar = true;
formSubOcr.ShowIcon = true;
}
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
ResetSubtitle();
//.........这里部分代码省略.........
示例5: LoadMp4Subtitle
private void LoadMp4Subtitle(string fileName, Trak mp4SubtitleTrack)
{
if (mp4SubtitleTrack.Mdia.IsVobSubSubtitle)
{
var subPicturesWithTimeCodes = new List<VobSubOcr.SubPicturesWithSeparateTimeCodes>();
for (int i = 0; i < mp4SubtitleTrack.Mdia.Minf.Stbl.EndTimeCodes.Count; i++)
{
if (mp4SubtitleTrack.Mdia.Minf.Stbl.SubPictures.Count > i)
{
var start = TimeSpan.FromSeconds(mp4SubtitleTrack.Mdia.Minf.Stbl.StartTimeCodes[i]);
var end = TimeSpan.FromSeconds(mp4SubtitleTrack.Mdia.Minf.Stbl.EndTimeCodes[i]);
subPicturesWithTimeCodes.Add(new VobSubOcr.SubPicturesWithSeparateTimeCodes(mp4SubtitleTrack.Mdia.Minf.Stbl.SubPictures[i], start, end));
}
}
using (var formSubOcr = new VobSubOcr())
{
formSubOcr.Initialize(subPicturesWithTimeCodes, Configuration.Settings.VobSubOcr, fileName); // TODO: language???
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
FileNew();
_subtitle.WasLoadedWithFrameNumbers = false;
foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
_subtitle.Paragraphs.Add(p);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
_subtitleListViewIndex = -1;
SubtitleListview1.FirstVisibleIndex = -1;
SubtitleListview1.SelectIndexAndEnsureVisible(0);
_fileName = Path.GetFileNameWithoutExtension(fileName);
_converted = true;
Text = Title;
Configuration.Settings.Save();
}
}
}
else
{
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
FileNew();
for (int i = 0; i < mp4SubtitleTrack.Mdia.Minf.Stbl.EndTimeCodes.Count; i++)
{
if (mp4SubtitleTrack.Mdia.Minf.Stbl.Texts.Count > i)
{
var start = TimeSpan.FromSeconds(mp4SubtitleTrack.Mdia.Minf.Stbl.StartTimeCodes[i]);
var end = TimeSpan.FromSeconds(mp4SubtitleTrack.Mdia.Minf.Stbl.EndTimeCodes[i]);
string text = mp4SubtitleTrack.Mdia.Minf.Stbl.Texts[i];
var p = new Paragraph(text, start.TotalMilliseconds, end.TotalMilliseconds);
if (p.EndTime.TotalMilliseconds - p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
if (mp4SubtitleTrack.Mdia.IsClosedCaption && string.IsNullOrEmpty(text))
{
// do not add empty lines
}
else
{
_subtitle.Paragraphs.Add(p);
}
}
}
SetEncoding(Encoding.UTF8);
ShowStatus(_language.SubtitleImportedFromMatroskaFile);
_subtitle.Renumber();
_subtitle.WasLoadedWithFrameNumbers = false;
if (fileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase))
{
_fileName = fileName.Substring(0, fileName.Length - 4);
Text = Title + " - " + _fileName;
}
else
{
Text = Title;
}
_fileDateTime = new DateTime();
_converted = true;
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
if (_subtitle.Paragraphs.Count > 0)
SubtitleListview1.SelectIndexAndEnsureVisible(0);
ShowSource();
}
}
示例6: ImportSubtitleFromTransportStream
private bool ImportSubtitleFromTransportStream(string fileName)
{
ShowStatus(_language.ParsingTransportStream);
Refresh();
var tsParser = new TransportStreamParser();
tsParser.Parse(fileName, (pos, total) => UpdateProgress(pos, total, _language.ParsingTransportStreamFile));
ShowStatus(string.Empty);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
if (tsParser.SubtitlePacketIds.Count == 0)
{
MessageBox.Show(_language.NoSubtitlesFound);
return false;
}
int packedId = tsParser.SubtitlePacketIds[0];
if (tsParser.SubtitlePacketIds.Count > 1)
{
using (var subChooser = new TransportStreamSubtitleChooser())
{
subChooser.Initialize(tsParser, fileName);
if (subChooser.ShowDialog(this) == DialogResult.Cancel)
return false;
packedId = tsParser.SubtitlePacketIds[subChooser.SelectedIndex];
}
}
var subtitles = tsParser.GetDvbSubtitles(packedId);
using (var formSubOcr = new VobSubOcr())
{
formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, fileName);
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);
_subtitle.Paragraphs.Clear();
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
_subtitle.WasLoadedWithFrameNumbers = false;
_subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
{
_subtitle.Paragraphs.Add(p);
}
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
_subtitleListViewIndex = -1;
SubtitleListview1.FirstVisibleIndex = -1;
SubtitleListview1.SelectIndexAndEnsureVisible(0);
_fileName = string.Empty;
Text = Title;
Configuration.Settings.Save();
return true;
}
return false;
}
}
示例7: LoadBluRaySubFromMatroska
private bool LoadBluRaySubFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
{
if (matroskaSubtitleInfo.ContentEncodingType == 1)
{
MessageBox.Show(_language.NoSupportEncryptedVobSub);
}
ShowStatus(_language.ParsingMatroskaFile);
Refresh();
Cursor.Current = Cursors.WaitCursor;
var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
Cursor.Current = Cursors.Default;
int noOfErrors = 0;
string lastError = string.Empty;
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
_subtitle.Paragraphs.Clear();
var subtitles = new List<BluRaySupParser.PcsData>();
var log = new StringBuilder();
foreach (var p in sub)
{
byte[] buffer = null;
if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
{
var outStream = new MemoryStream();
var outZStream = new zlib.ZOutputStream(outStream);
var inStream = new MemoryStream(p.Data);
try
{
CopyStream(inStream, outZStream);
buffer = new byte[outZStream.TotalOut];
outStream.Position = 0;
outStream.Read(buffer, 0, buffer.Length);
}
catch (Exception exception)
{
var tc = new TimeCode(p.Start);
lastError = tc + ": " + exception.Message + ": " + exception.StackTrace;
noOfErrors++;
}
finally
{
outZStream.Close();
inStream.Close();
}
}
else
{
buffer = p.Data;
}
if (buffer != null && buffer.Length > 100)
{
var ms = new MemoryStream(buffer);
var list = BluRaySupParser.ParseBluRaySup(ms, log, true);
foreach (var sup in list)
{
sup.StartTime = (long)((p.Start - 1) * 90.0);
sup.EndTime = (long)((p.End - 1) * 90.0);
subtitles.Add(sup);
// fix overlapping
if (subtitles.Count > 1 && sub[subtitles.Count - 2].End > sub[subtitles.Count - 1].Start)
subtitles[subtitles.Count - 2].EndTime = subtitles[subtitles.Count - 1].StartTime - 1;
}
ms.Close();
}
else if (subtitles.Count > 0)
{
var lastSub = subtitles[subtitles.Count - 1];
if (lastSub.StartTime == lastSub.EndTime)
{
lastSub.EndTime = (long)((p.Start - 1) * 90.0);
if (lastSub.EndTime - lastSub.StartTime > 1000000)
lastSub.EndTime = lastSub.StartTime;
}
}
}
if (noOfErrors > 0)
{
MessageBox.Show(string.Format("{0} error(s) occurred during extraction of bdsup\r\n\r\n{1}", noOfErrors, lastError));
}
using (var formSubOcr = new VobSubOcr())
{
formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, matroska.Path);
if (_loading)
{
formSubOcr.Icon = (Icon)Icon.Clone();
formSubOcr.ShowInTaskbar = true;
formSubOcr.ShowIcon = true;
}
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);
_subtitle.Paragraphs.Clear();
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
//.........这里部分代码省略.........
示例8: ImportAndOcrSrt
private void ImportAndOcrSrt(Subtitle subtitle)
{
using (var formSubOcr = new VobSubOcr())
{
formSubOcr.Initialize(subtitle, Configuration.Settings.VobSubOcr, false);
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeImportingBdnXml);
FileNew();
_subtitle.Paragraphs.Clear();
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
_subtitle.WasLoadedWithFrameNumbers = false;
_subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
{
_subtitle.Paragraphs.Add(p);
}
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
_subtitleListViewIndex = -1;
SubtitleListview1.FirstVisibleIndex = -1;
SubtitleListview1.SelectIndexAndEnsureVisible(0);
_fileName = Path.ChangeExtension(formSubOcr.FileName, ".srt");
SetTitle();
_converted = true;
}
}
}
示例9: ToolStripMenuItemImportDvdSubtitlesClick
private void ToolStripMenuItemImportDvdSubtitlesClick(object sender, EventArgs e)
{
if (!ContinueNewOrExit())
{
return;
}
using (var formSubRip = new DvdSubRip(Handle))
{
if (formSubRip.ShowDialog(this) == DialogResult.OK)
{
using (var showSubtitles = new DvdSubRipChooseLanguage())
{
showSubtitles.Initialize(formSubRip.MergedVobSubPacks, formSubRip.Palette, formSubRip.Languages, formSubRip.SelectedLanguage);
if (formSubRip.Languages.Count == 1 || showSubtitles.ShowDialog(this) == DialogResult.OK)
{
using (var formSubOcr = new VobSubOcr())
{
var subs = formSubRip.MergedVobSubPacks;
if (showSubtitles.SelectedVobSubMergedPacks != null)
subs = showSubtitles.SelectedVobSubMergedPacks;
formSubOcr.Initialize(subs, formSubRip.Palette, Configuration.Settings.VobSubOcr, formSubRip.SelectedLanguage);
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);
FileNew();
_subtitle.Paragraphs.Clear();
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
_subtitle.WasLoadedWithFrameNumbers = false;
_subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
{
_subtitle.Paragraphs.Add(p);
}
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
_subtitleListViewIndex = -1;
SubtitleListview1.FirstVisibleIndex = -1;
SubtitleListview1.SelectIndexAndEnsureVisible(0, true);
_fileName = string.Empty;
Text = Title;
Configuration.Settings.Save();
}
}
}
}
}
}
}
示例10: Initialize
internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink, VobSubOcr.CompareMatch bestGuess, List<VobSubOcr.ImageCompareAddition> additions, VobSubOcr vobSubForm)
{
ShrinkSelection = false;
ExpandSelection = false;
textBoxCharacters.Text = string.Empty;
if (bestGuess != null)
{
buttonGuess.Visible = false; // hm... not too useful :(
buttonGuess.Text = bestGuess.Text;
}
else
{
buttonGuess.Visible = false;
}
_vobSubForm = vobSubForm;
_additions = additions;
buttonShrinkSelection.Visible = showShrink;
checkBoxItalic.Checked = italicChecked;
if (position.X != -1 && position.Y != -1)
{
StartPosition = FormStartPosition.Manual;
Left = position.X;
Top = position.Y;
}
pictureBoxSubtitleImage.Image = vobSubImage;
pictureBoxCharacter.Image = character.NikseBitmap.GetBitmap();
if (_additions.Count > 0)
{
var last = _additions[_additions.Count - 1];
buttonLastEdit.Visible = true;
if (last.Italic)
buttonLastEdit.Font = new System.Drawing.Font(buttonLastEdit.Font.FontFamily, buttonLastEdit.Font.Size, FontStyle.Italic);
else
buttonLastEdit.Font = new System.Drawing.Font(buttonLastEdit.Font.FontFamily, buttonLastEdit.Font.Size);
pictureBoxLastEdit.Visible = true;
pictureBoxLastEdit.Image = last.Image.GetBitmap();
buttonLastEdit.Text = string.Format(Configuration.Settings.Language.VobSubOcrCharacter.EditLastX, last.Text);
pictureBoxLastEdit.Top = buttonLastEdit.Top - last.Image.Height + buttonLastEdit.Height;
}
else
{
buttonLastEdit.Visible = false;
pictureBoxLastEdit.Visible = false;
}
Bitmap org = (Bitmap)vobSubImage.Clone();
Bitmap bm = new Bitmap(org.Width, org.Height);
Graphics g = Graphics.FromImage(bm);
g.DrawImage(org, 0, 0, org.Width, org.Height);
g.DrawRectangle(Pens.Red, character.X, character.Y, character.NikseBitmap.Width, character.NikseBitmap.Height - 1);
g.Dispose();
pictureBoxSubtitleImage.Image = bm;
pictureBoxCharacter.Top = labelCharacters.Top + 16;
pictureBoxLastEdit.Left = buttonLastEdit.Left + buttonLastEdit.Width + 5;
}
示例11: ImportAndOcrSon
private void ImportAndOcrSon(string fileName, Son format, List<string> list)
{
using (var formSubOcr = new VobSubOcr())
{
var sub = new Subtitle();
format.LoadSubtitle(sub, list, fileName);
sub.FileName = fileName;
formSubOcr.Initialize(sub, Configuration.Settings.VobSubOcr, true);
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
this.MakeHistoryForUndo(this._language.BeforeImportingBdnXml);
this.FileNew();
this._subtitle.Paragraphs.Clear();
this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
this._subtitle.WasLoadedWithFrameNumbers = false;
this._subtitle.CalculateFrameNumbersFromTimeCodes(this.CurrentFrameRate);
foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
{
this._subtitle.Paragraphs.Add(p);
}
this.ShowSource();
this.SubtitleListview1.Fill(this._subtitle, this._subtitleAlternate);
this._subtitleListViewIndex = -1;
this.SubtitleListview1.FirstVisibleIndex = -1;
this.SubtitleListview1.SelectIndexAndEnsureVisible(0);
this._fileName = Path.ChangeExtension(formSubOcr.FileName, ".srt");
this.SetTitle();
this._converted = true;
}
}
}
示例12: buttonConvert_Click
//.........这里部分代码省略.........
IncrementAndShowProgress();
}
else
{
if (isMatroska && (Path.GetExtension(fileName).Equals(".mkv", StringComparison.OrdinalIgnoreCase) || Path.GetExtension(fileName).Equals(".mks", StringComparison.OrdinalIgnoreCase)))
{
using (var matroska = new MatroskaFile(fileName))
{
if (matroska.IsValid)
{
foreach (var track in matroska.GetTracks(true))
{
if (track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
{
// TODO: Convert from VobSub image based format!
}
else if (track.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
{
// TODO: Convert from Blu-ray image based format!
}
else if (track.CodecId.Equals("S_TEXT/UTF8", StringComparison.OrdinalIgnoreCase) || track.CodecId.Equals("S_TEXT/SSA", StringComparison.OrdinalIgnoreCase) || track.CodecId.Equals("S_TEXT/ASS", StringComparison.OrdinalIgnoreCase))
{
var mkvSub = matroska.GetSubtitle(track.TrackNumber, null);
Utilities.LoadMatroskaTextSubtitle(track, matroska, mkvSub, sub);
break;
}
}
}
}
}
else if (bluRaySubtitles.Count > 0)
{
item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.Ocr;
using (var vobSubOcr = new VobSubOcr())
{
vobSubOcr.FileName = Path.GetFileName(fileName);
vobSubOcr.InitializeBatch(bluRaySubtitles, Configuration.Settings.VobSubOcr, fileName);
sub = vobSubOcr.SubtitleFromOcr;
}
}
else if (isVobSub)
{
item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.Ocr;
using (var vobSubOcr = new VobSubOcr())
{
vobSubOcr.InitializeBatch(fileName, Configuration.Settings.VobSubOcr);
sub = vobSubOcr.SubtitleFromOcr;
}
}
if (comboBoxSubtitleFormats.Text == AdvancedSubStationAlpha.NameOfFormat && _assStyle != null)
{
sub.Header = _assStyle;
}
else if (comboBoxSubtitleFormats.Text == SubStationAlpha.NameOfFormat && _ssaStyle != null)
{
sub.Header = _ssaStyle;
}
bool skip = CheckSkipFilter(fileName, format, sub);
if (skip)
{
item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.FilterSkipped;
}
else
{
foreach (Paragraph p in sub.Paragraphs)
示例13: InitializeFromVobSubOcr
internal void InitializeFromVobSubOcr(Subtitle subtitle, SubtitleFormat format, string exportType, string fileName, VobSubOcr vobSubOcr, string languageString)
{
_vobSubOcr = vobSubOcr;
Initialize(subtitle, format, exportType, fileName, null);
//set language
if (!string.IsNullOrEmpty(languageString))
{
if (languageString.Contains("(") && !languageString.StartsWith("("))
languageString = languageString.Substring(0, languageString.IndexOf("(", StringComparison.Ordinal) - 1).Trim();
for (int i = 0; i < comboBoxLanguage.Items.Count; i++)
{
string l = comboBoxLanguage.Items[i].ToString();
if (l == languageString && i < comboBoxLanguage.Items.Count)
comboBoxLanguage.SelectedIndex = i;
}
}
//Disable options not available when exporting existing images
comboBoxSubtitleFont.Enabled = false;
comboBoxSubtitleFontSize.Enabled = false;
buttonColor.Visible = false;
panelColor.Visible = false;
checkBoxBold.Visible = false;
checkBoxSimpleRender.Visible = false;
comboBox3D.Enabled = false;
numericUpDownDepth3D.Enabled = false;
buttonBorderColor.Visible = false;
panelBorderColor.Visible = false;
labelBorderWidth.Visible = false;
comboBoxBorderWidth.Visible = false;
buttonShadowColor.Visible = false;
panelShadowColor.Visible = false;
labelShadowWidth.Visible = false;
comboBoxShadowWidth.Visible = false;
labelShadowTransparency.Visible = false;
numericUpDownShadowTransparency.Visible = false;
labelLineHeight.Visible = false;
numericUpDownLineSpacing.Visible = false;
}
示例14: ConvertVobSubSubtitle
private static void ConvertVobSubSubtitle(string fileName, string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, bool overwrite, string pacCodePage, double? targetFrameRate)
{
var format = Utilities.GetSubtitleFormatByFriendlyName(toFormat) ?? new SubRip();
Console.WriteLine("Loading subtitles from file \"{0}\"", fileName);
Subtitle sub;
using (var vobSubOcr = new VobSubOcr())
{
Console.WriteLine("Using OCR to extract subtitles");
vobSubOcr.InitializeBatch(fileName, Configuration.Settings.VobSubOcr);
sub = vobSubOcr.SubtitleFromOcr;
Console.WriteLine("Extracted subtitles from file \"{0}\"", fileName);
}
if (sub != null)
{
Console.WriteLine("Converted subtitle");
BatchConvertSave(toFormat, offset, targetEncoding, outputFolder, count, ref converted, ref errors, formats, fileName, sub, format, overwrite, pacCodePage, targetFrameRate);
}
}
示例15: ConvertBluRaySubtitle
private static void ConvertBluRaySubtitle(string fileName, string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, bool overwrite, string pacCodePage, double? targetFrameRate, bool removeTextForHi, bool fixCommonErrors, bool redoCasing)
{
SubtitleFormat format = Utilities.GetSubtitleFormatByFriendlyName(toFormat) ?? new SubRip();
var log = new StringBuilder();
Console.WriteLine("Loading subtitles from file \"{0}\"", fileName);
var bluRaySubtitles = BluRaySupParser.ParseBluRaySup(fileName, log);
Subtitle sub;
using (var vobSubOcr = new VobSubOcr())
{
Console.WriteLine("Using OCR to extract subtitles");
vobSubOcr.FileName = Path.GetFileName(fileName);
vobSubOcr.InitializeBatch(bluRaySubtitles, Configuration.Settings.VobSubOcr, fileName);
sub = vobSubOcr.SubtitleFromOcr;
Console.WriteLine("Extracted subtitles from file \"{0}\"", fileName);
}
if (sub != null)
{
Console.WriteLine("Converted subtitle");
BatchConvertSave(toFormat, offset, targetEncoding, outputFolder, count, ref converted, ref errors, formats, fileName, sub, format, overwrite, pacCodePage, targetFrameRate, removeTextForHi, fixCommonErrors, redoCasing);
}
}