示例#1
0
文件: Scale.cs 项目: RicRep/ShareX
        public override Image Apply(Image img)
        {
            if (WidthPercentage <= 0 && HeightPercentage <= 0)
            {
                return(img);
            }

            float widthPercentage  = WidthPercentage <= 0 ? HeightPercentage : WidthPercentage;
            float heightPercentage = HeightPercentage <= 0 ? WidthPercentage : HeightPercentage;

            return(ImageResizeHelpers.ResizeImageByPercentage(img, widthPercentage, heightPercentage));
        }
示例#2
0
文件: Resize.cs 项目: RicRep/ShareX
        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));
        }
示例#3
0
        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;
        }
示例#4
0
        public NotificationForm(int duration, int fadeDuration, ContentAlignment placement, Size size, NotificationFormConfig config)
        {
            InitializeComponent();
            Icon = ShareXResources.Icon;
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);

            Duration     = duration;
            FadeDuration = fadeDuration;

            opacityDecrement = (float)fadeInterval / FadeDuration;

            ToastConfig = config;
            textFont    = new Font("Arial", 10);

            if (config.Image != null)
            {
                config.Image = ImageResizeHelpers.ResizeImageLimit(config.Image, size);
                config.Image = ImageDrawHelpers.DrawCheckers(config.Image);
                size         = new Size(config.Image.Width + 2, config.Image.Height + 2);
            }
            else if (!string.IsNullOrEmpty(config.Text))
            {
                textRenderSize = Helpers.MeasureText(config.Text, textFont, size.Width - textPadding * 2);
                size           = new Size(textRenderSize.Width + textPadding * 2, textRenderSize.Height + textPadding * 2 + 2);
            }

            Point position = Helpers.GetPosition(placement, new Point(windowOffset, windowOffset), Screen.PrimaryScreen.WorkingArea.Size, size);

            NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X,
                                       position.Y + Screen.PrimaryScreen.WorkingArea.Y, size.Width, size.Height, SetWindowPosFlags.SWP_NOACTIVATE);

            if (Duration <= 0)
            {
                DurationEnd();
            }
            else
            {
                tDuration.Interval = Duration;
                tDuration.Start();
            }
        }
示例#5
0
        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();
                    }
                }
            }
        }