public override Image Apply(Image img) { if (Width <= 0 && Height <= 0) { return(img); } int width = Width <= 0 ? (int)((float)Height / img.Height * img.Width) : Width; int height = Height <= 0 ? (int)((float)Width / img.Width * img.Height) : Height; if ((Mode == ResizeMode.ResizeIfBigger && img.Width <= width && img.Height <= height) || (Mode == ResizeMode.ResizeIfSmaller && img.Width >= width && img.Height >= height)) { return(img); } return(ImageResizeHelpers.ResizeImage(img, width, height)); }
public FirstTimeConfigForm() { InitializeComponent(); pbLogo.Image = ImageResizeHelpers.ResizeImage(ShareXResources.Logo, 128, 128); StartupTaskState state = StartupManagerFactory.StartupManager.State; cbRunStartup.Checked = state == StartupTaskState.Enabled; cbRunStartup.Enabled = state != StartupTaskState.DisabledByUser; cbShellContextMenuButton.Checked = IntegrationHelpers.CheckShellContextMenuButton(); cbSendToMenu.Checked = IntegrationHelpers.CheckSendToMenuButton(); #if STEAM cbSteamInApp.Checked = IntegrationHelpers.CheckSteamShowInApp(); #else cbSteamInApp.Visible = false; #endif loaded = true; }
private Image CombineScreenshots(List <VideoThumbnailInfo> thumbnails) { List <Image> images = new List <Image>(); Image finalImage = null; try { string infoString = ""; int infoStringHeight = 0; if (Options.AddVideoInfo) { infoString = VideoInfo.ToString(); using (Font font = new Font("Arial", 12)) { infoStringHeight = Helpers.MeasureText(infoString, font).Height; } } foreach (VideoThumbnailInfo thumbnail in thumbnails) { Image img = ImageHelpers.LoadImage(thumbnail.Filepath); if (Options.MaxThumbnailWidth > 0 && img.Width > Options.MaxThumbnailWidth) { int maxThumbnailHeight = (int)((float)Options.MaxThumbnailWidth / img.Width * img.Height); img = ImageResizeHelpers.ResizeImage(img, Options.MaxThumbnailWidth, maxThumbnailHeight); } images.Add(img); } int columnCount = Options.ColumnCount; int thumbWidth = images[0].Width; int width = Options.Padding * 2 + thumbWidth * columnCount + (columnCount - 1) * Options.Spacing; int rowCount = (int)Math.Ceiling(images.Count / (float)columnCount); int thumbHeight = images[0].Height; int height = Options.Padding * 3 + infoStringHeight + thumbHeight * rowCount + (rowCount - 1) * Options.Spacing; finalImage = new Bitmap(width, height); using (Graphics g = Graphics.FromImage(finalImage)) { g.Clear(Color.WhiteSmoke); if (!string.IsNullOrEmpty(infoString)) { using (Font font = new Font("Arial", 12)) { g.DrawString(infoString, font, Brushes.Black, Options.Padding, Options.Padding); } } int i = 0; int offsetY = Options.Padding * 2 + infoStringHeight; for (int y = 0; y < rowCount; y++) { int offsetX = Options.Padding; for (int x = 0; x < columnCount; x++) { if (Options.DrawShadow) { int shadowOffset = 3; using (Brush shadowBrush = new SolidBrush(Color.FromArgb(75, Color.Black))) { g.FillRectangle(shadowBrush, offsetX + shadowOffset, offsetY + shadowOffset, thumbWidth, thumbHeight); } } g.DrawImage(images[i], offsetX, offsetY, thumbWidth, thumbHeight); if (Options.DrawBorder) { g.DrawRectangleProper(Pens.Black, offsetX, offsetY, thumbWidth, thumbHeight); } if (Options.AddTimestamp) { int timestampOffset = 10; using (Font font = new Font("Arial", 10, FontStyle.Bold)) { g.DrawTextWithShadow(thumbnails[i].Timestamp.ToString(), new Point(offsetX + timestampOffset, offsetY + timestampOffset), font, Brushes.White, Brushes.Black); } } i++; if (i >= images.Count) { return(finalImage); } offsetX += thumbWidth + Options.Spacing; } offsetY += thumbHeight + Options.Spacing; } } return(finalImage); } catch { if (finalImage != null) { finalImage.Dispose(); } throw; } finally { foreach (Image image in images) { if (image != null) { image.Dispose(); } } } }