void ResizeForm_Load(object sender, EventArgs e) { FFMSSharp.Frame frame = Program.VideoSource.GetFrame((Filters.Trim == null) ? 0 : Filters.Trim.TrimStart); // the video may have different frame resolutions if (Filters.Crop != null) { inwidth = frame.EncodedResolution.Width - Filters.Crop.Left + Filters.Crop.Right; inheight = frame.EncodedResolution.Height - Filters.Crop.Top + Filters.Crop.Bottom; } else { if ((Owner as MainForm).SarCompensate) { inwidth = (Owner as MainForm).SarWidth; inheight = (Owner as MainForm).SarHeight; } else { inwidth = frame.EncodedResolution.Width; inheight = frame.EncodedResolution.Height; } } labelWidthIn.Text = inwidth.ToString(); textWidthOut.Text = inwidth.ToString(); labelHeightIn.Text = inheight.ToString(); textHeightOut.Text = inheight.ToString(); textWidthOut.TextChanged += textWidthOut_TextChanged; textHeightOut.TextChanged += textHeightOut_TextChanged; }
public void GeneratePreview(bool force = false) { if (Program.VideoSource == null) return; if (force) cachedframenumber = -1; // Load the frame, if we haven't already if (cachedframenumber != framenumber) { cachedframenumber = (int)framenumber; frame = Program.VideoSource.GetFrame(cachedframenumber); } // Calculate width and height int width, height; float scale; scale = Math.Min((float)this.Size.Width / (float)frame.EncodedResolution.Width, (float)this.Size.Height / (float)frame.EncodedResolution.Height); width = (int)(frame.EncodedResolution.Width * scale); height = (int)(frame.EncodedResolution.Height * scale); // http://stackoverflow.com/a/24199315/174466 var destRect = new Rectangle(0, 0, width, height); var destImage = new Bitmap(width, height); destImage.SetResolution(frame.EncodedResolution.Width, frame.EncodedResolution.Height); using (var graphics = Graphics.FromImage(destImage)) { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapMode = new ImageAttributes()) { wrapMode.SetWrapMode(WrapMode.TileFlipXY); graphics.DrawImage(frame.Bitmap, destRect, 0, 0, frame.EncodedResolution.Width, frame.EncodedResolution.Height, GraphicsUnit.Pixel, wrapMode); } } Picture.BackgroundImage = destImage; Picture.ClientSize = new Size(width, height); // Center the pictureBox in our control if (width == Width || width - 1 == Width || width + 1 == Width) // this looks weird but keep in mind we're dealing with an ex float here { Padding = new Padding(0, (Height - height) / 2, 0, 0); } else { Padding = new Padding((Width - width) / 2, 0, 0, 0); } }
private void buttonConfirm_Click(object sender, EventArgs e) { if (cropPercent.Left >= cropPercent.Right || cropPercent.Top >= cropPercent.Bottom) { MessageBox.Show("You messed up your crop! Please try again.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); cropPercent = new RectangleF(0.25f, 0.25f, 0.5f, 0.5f); return; } float tolerance = 0.1f; //Account for float inprecision if (cropPercent.Left < 0 - tolerance || cropPercent.Top < 0 - tolerance || cropPercent.Right > 1 + tolerance || cropPercent.Bottom > 1 + tolerance) { MessageBox.Show("Your crop is outside the valid range! Please try again.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); cropPercent = new RectangleF(0.25f, 0.25f, 0.5f, 0.5f); return; } cropPercent.X = Math.Max(0, cropPercent.X); cropPercent.Y = Math.Max(0, cropPercent.Y); if (cropPercent.Right > 1) { cropPercent.Width = 1 - cropPercent.X; } if (cropPercent.Bottom > 1) { cropPercent.Height = 1 - cropPercent.Y; } int width, height; if ((Owner as MainForm).SarCompensate) { width = (Owner as MainForm).SarWidth; height = (Owner as MainForm).SarHeight; } else { FFMSSharp.Frame frame = Program.VideoSource.GetFrame(previewFrame.Frame); width = frame.EncodedResolution.Width; height = frame.EncodedResolution.Height; } GeneratedFilter = new CropFilter( (int)(width * cropPercent.Left), (int)(height * cropPercent.Top), -(int)(width - width * cropPercent.Right), -(int)(height - height * cropPercent.Bottom) ); DialogResult = DialogResult.OK; Close(); }
void CropForm_Load(object sender, EventArgs e) { if (InputFilter == null) { cropPercent = new RectangleF(0.25f, 0.25f, 0.5f, 0.5f); } else { int width, height; if ((Owner as MainForm).SarCompensate) { width = (Owner as MainForm).SarWidth; height = (Owner as MainForm).SarHeight; } else { // Note that because we call this, the frame used by the PreviewFrame gets disposed. We need to call GeneratePreview after we're done with this. FFMSSharp.Frame frame = Program.VideoSource.GetFrame(previewFrame.Frame); width = frame.EncodedResolution.Width; height = frame.EncodedResolution.Height; } cropPercent = new RectangleF( (float)InputFilter.Left / (float)width, (float)InputFilter.Top / (float)height, (float)(width - InputFilter.Left + InputFilter.Right) / (float)width, (float)(height - InputFilter.Top + InputFilter.Bottom) / (float)height ); previewFrame.GeneratePreview(true); } if ((Owner as MainForm).boxAdvancedScripting.Checked) { return; } if (Filters.Trim != null) { previewFrame.Frame = Filters.Trim.TrimStart; trimTimingToolStripMenuItem.Enabled = true; } if (Filters.MultipleTrim != null) { previewFrame.Frame = Filters.MultipleTrim.Trims[0].TrimStart; trimTimingToolStripMenuItem.Enabled = true; } }
void OverlayForm_Load(object sender, EventArgs e) { if (InputFilter == null) { if (filePicker.ShowDialog(this) == DialogResult.Cancel) { DialogResult = DialogResult.Cancel; Close(); return; } filename = filePicker.FileName; point = new Point(0, 0); } else { filename = InputFilter.FileName; point = InputFilter.Placement; } picture = new Bitmap(filename); if ((Owner as MainForm).SarCompensate) { videoResolution = new Size((Owner as MainForm).SarWidth, (Owner as MainForm).SarHeight); } else { FFMSSharp.Frame frame = Program.VideoSource.GetFrame(previewFrame.Frame); videoResolution = frame.EncodedResolution; previewFrame.GeneratePreview(true); } if ((Owner as MainForm).boxAdvancedScripting.Checked) { return; } if (Filters.Trim != null) { previewFrame.Frame = Filters.Trim.TrimStart; trimTimingToolStripMenuItem.Enabled = true; } if (Filters.MultipleTrim != null) { previewFrame.Frame = Filters.MultipleTrim.Trims[0].TrimStart; trimTimingToolStripMenuItem.Enabled = true; } }
void CaptionForm_Load(object sender, EventArgs e) { if (InputFilter != null) { point = InputFilter.Placement; boxText.Text = InputFilter.Text; fontDialog1.Font = InputFilter.Style; colorDialogTextColor.Color = InputFilter.TextColor; colorDialogBorderColor.Color = InputFilter.BorderColor; numericBorderThickness.Value = InputFilter.BorderThickness; } if ((Owner as MainForm).SarCompensate) { videoResolution = new Size((Owner as MainForm).SarWidth, (Owner as MainForm).SarHeight); } else { FFMSSharp.Frame frame = Program.VideoSource.GetFrame(previewFrame.Frame); videoResolution = frame.EncodedResolution; previewFrame.GeneratePreview(true); } if ((Owner as MainForm).boxAdvancedScripting.Checked) { return; } if (Filters.Trim != null) { previewFrame.Frame = Filters.Trim.TrimStart; trimTimingToolStripMenuItem.Enabled = true; } if (Filters.MultipleTrim != null) { previewFrame.Frame = Filters.MultipleTrim.Trims[0].TrimStart; trimTimingToolStripMenuItem.Enabled = true; } }
public void GeneratePreview(bool force = false) { if (Program.VideoSource == null) { return; } if (force) { cachedframenumber = -1; } // Load the frame, if we haven't already if (cachedframenumber != framenumber) { cachedframenumber = (int)framenumber; frame = Program.VideoSource.GetFrame(cachedframenumber); } // Calculate width and height int width, height; float scale; scale = Math.Min((float)this.Size.Width / (float)frame.EncodedResolution.Width, (float)this.Size.Height / (float)frame.EncodedResolution.Height); width = (int)(frame.EncodedResolution.Width * scale); height = (int)(frame.EncodedResolution.Height * scale); // http://stackoverflow.com/a/24199315/174466 var destRect = new Rectangle(0, 0, width, height); var destImage = new Bitmap(width, height); destImage.SetResolution(frame.EncodedResolution.Width, frame.EncodedResolution.Height); using (var graphics = Graphics.FromImage(destImage)) { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapMode = new ImageAttributes()) { wrapMode.SetWrapMode(WrapMode.TileFlipXY); graphics.DrawImage(frame.Bitmap, destRect, 0, 0, frame.EncodedResolution.Width, frame.EncodedResolution.Height, GraphicsUnit.Pixel, wrapMode); } } Picture.BackgroundImage = destImage; Picture.ClientSize = new Size(width, height); // Center the pictureBox in our control if (width == Width || width - 1 == Width || width + 1 == Width) // this looks weird but keep in mind we're dealing with an ex float here { Padding = new Padding(0, (Height - height) / 2, 0, 0); } else { Padding = new Padding((Width - width) / 2, 0, 0, 0); } }