Example #1
0
        private void subtitleListView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (subtitleListView1.SelectedItems.Count < 1)
            {
                timeUpDownStartTime.TimeCode = new TimeCode();
                timeUpDownEndTime.TimeCode   = new TimeCode();
                numericUpDownX.Value         = 0;
                numericUpDownY.Value         = 0;
                pictureBoxMovableImage.Image?.Dispose();
                pictureBoxScreen.Image?.Dispose();
                return;
            }

            var idx = subtitleListView1.SelectedItems[0].Index;

            if (_bluRaySubtitles != null)
            {
                var sub   = _bluRaySubtitles[idx];
                var extra = _extra[idx];
                timeUpDownStartTime.TimeCode = sub.StartTimeCode;
                timeUpDownEndTime.TimeCode   = sub.EndTimeCode;
                checkBoxIsForced.Checked     = extra.Forced;
                numericUpDownX.Value         = extra.X;
                numericUpDownY.Value         = extra.Y;
                pictureBoxMovableImage.Image?.Dispose();
                pictureBoxScreen.Image?.Dispose();
                var bmp         = extra.Bitmap != null ? (Bitmap)extra.Bitmap.Clone() : sub.GetBitmap();
                var nikseBitmap = new NikseBitmap(bmp);
                nikseBitmap.ReplaceTransparentWith(Color.Black);
                bmp.Dispose();
                bmp = nikseBitmap.GetBitmap();
                var screenBmp = new Bitmap((int)numericUpDownScreenWidth.Value, (int)numericUpDownScreenHeight.Value);
                using (var g = Graphics.FromImage(screenBmp))
                {
                    using (var brush = new SolidBrush(Color.Black))
                    {
                        g.FillRectangle(brush, 0, 0, screenBmp.Width, screenBmp.Height);
                    }
                    //g.DrawImage(bmp, extra.X, extra.Y);
                }

                pictureBoxMovableImage.Width = bmp.Width;
                var widthAspect  = pictureBoxScreen.Width / numericUpDownScreenWidth.Value;
                var heightAspect = pictureBoxScreen.Height / numericUpDownScreenHeight.Value;
                var scaledBmp    = VobSubOcr.ResizeBitmap(bmp, (int)Math.Round(bmp.Width * widthAspect), (int)Math.Round(bmp.Height * heightAspect));
                pictureBoxMovableImage.Width    = scaledBmp.Width;
                pictureBoxMovableImage.Height   = scaledBmp.Height;
                pictureBoxMovableImage.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBoxMovableImage.Image    = scaledBmp;
                pictureBoxMovableImage.Left     = (int)Math.Round(extra.X * widthAspect);
                pictureBoxMovableImage.Top      = (int)Math.Round(extra.Y * heightAspect);
                pictureBoxScreen.Image          = screenBmp;
                labelCurrentSize.Text           = string.Format("Size: {0}x{1}", bmp.Width, bmp.Height);
            }
        }
Example #2
0
        private void ListBoxFileNamesSelectedIndexChanged(object sender, EventArgs e)
        {
            checkBoxItalic.Checked = _italics[listBoxFileNames.SelectedIndex];
            string name         = listBoxFileNames.Items[listBoxFileNames.SelectedIndex].ToString();
            string databaseName = _directoryPath + "Images.db";
            Bitmap bmp          = null;

            labelExpandCount.Text = string.Empty;
            labelImageInfo.Text   = string.Empty;
            if (_binOcrDb != null)
            {
                var bob = GetSelectedBinOcrBitmap();
                if (bob != null)
                {
                    bmp = bob.ToOldBitmap();
                    labelImageInfo.Text = string.Format("Top:{0}, {1} colored pixels of {2}", bob.Y, bob.NumberOfColoredPixels, (bob.Width * bob.Height));

                    //bool italicI;
                    //var isI = bob.IsLowercaseI(out italicI);
                    //labelImageInfo.Text = string.Format("T:{0} j{1} :{2} i{3}{4} '{5} #{6}/{7}", bob.Y, bob.IsLowercaseJ(), bob.IsColon(), isI, italicI ? "i" : "", bob.IsApostrophe(), bob.NumberOfColoredPixels, (bob.Width * bob.Height));

                    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;
            pictureBox1.Width    = bmp.Width + 2;
            pictureBox1.Height   = bmp.Height + 2;
            pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;

            var bmp2 = VobSubOcr.ResizeBitmap(bmp, bmp.Width * 2, bmp.Height * 2);

            pictureBox2.Image    = bmp2;
            pictureBox2.Width    = bmp2.Width + 2;
            pictureBox2.Height   = bmp2.Height + 2;
            pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;

            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, StringComparison.Ordinal))
                        {
                            textBoxText.Text = a.Text;
                            break;
                        }
                    }
                }
            }
        }