Esempio n. 1
0
 public override Image Apply(Image img)
 {
     return(ImageHelpers.DrawBorder(img, Type, Color, Size));
 }
Esempio n. 2
0
        private Image CombineScreenshots(List <VideoThumbnailInfo> thumbnails)
        {
            List <Bitmap> images     = new List <Bitmap>();
            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)
                {
                    Bitmap bmp = ImageHelpers.LoadImage(thumbnail.Filepath);

                    if (Options.MaxThumbnailWidth > 0 && bmp.Width > Options.MaxThumbnailWidth)
                    {
                        int maxThumbnailHeight = (int)((float)Options.MaxThumbnailWidth / bmp.Width * bmp.Height);
                        bmp = ImageHelpers.ResizeImage(bmp, Options.MaxThumbnailWidth, maxThumbnailHeight);
                    }

                    images.Add(bmp);
                }

                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 (Bitmap image in images)
                {
                    if (image != null)
                    {
                        image.Dispose();
                    }
                }
            }
        }
Esempio n. 3
0
        private void UpdateMenu()
        {
            if (menuForm == null)
            {
                return;
            }

            ShapeType shapeType = CurrentShapeType;

            foreach (ToolStripButton tsb in tsMain.Items.OfType <ToolStripButton>().Where(x => x.Tag is ShapeType))
            {
                if ((ShapeType)tsb.Tag == shapeType)
                {
                    tsb.RadioCheck();
                    break;
                }
            }

            Color borderColor;

            if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
            {
                borderColor = AnnotationOptions.TextBorderColor;
            }
            else if (shapeType == ShapeType.DrawingTextOutline)
            {
                borderColor = AnnotationOptions.TextOutlineBorderColor;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                borderColor = AnnotationOptions.StepBorderColor;
            }
            else
            {
                borderColor = AnnotationOptions.BorderColor;
            }

            if (tsbBorderColor.Image != null)
            {
                tsbBorderColor.Image.Dispose();
            }
            tsbBorderColor.Image = ImageHelpers.CreateColorPickerIcon(borderColor, new Rectangle(0, 0, 16, 16), 8);

            int borderSize;

            if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
            {
                borderSize = AnnotationOptions.TextBorderSize;
            }
            else if (shapeType == ShapeType.DrawingTextOutline)
            {
                borderSize = AnnotationOptions.TextOutlineBorderSize;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                borderSize = AnnotationOptions.StepBorderSize;
            }
            else
            {
                borderSize = AnnotationOptions.BorderSize;
            }

            tslnudBorderSize.Content.Value = borderSize;

            Color fillColor;

            if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon)
            {
                fillColor = AnnotationOptions.TextFillColor;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                fillColor = AnnotationOptions.StepFillColor;
            }
            else
            {
                fillColor = AnnotationOptions.FillColor;
            }

            if (tsbFillColor.Image != null)
            {
                tsbFillColor.Image.Dispose();
            }
            tsbFillColor.Image = ImageHelpers.CreateColorPickerIcon(fillColor, new Rectangle(0, 0, 16, 16));

            int cornerRadius = 0;

            if (shapeType == ShapeType.RegionRectangle)
            {
                cornerRadius = AnnotationOptions.RegionCornerRadius;
            }
            else if (shapeType == ShapeType.DrawingRectangle || shapeType == ShapeType.DrawingTextBackground)
            {
                cornerRadius = AnnotationOptions.DrawingCornerRadius;
            }

            tslnudCornerRadius.Content.Value = cornerRadius;

            tslnudBlurRadius.Content.Value = AnnotationOptions.BlurRadius;

            tslnudPixelateSize.Content.Value = AnnotationOptions.PixelateSize;

            if (tsbHighlightColor.Image != null)
            {
                tsbHighlightColor.Image.Dispose();
            }
            tsbHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.HighlightColor, new Rectangle(0, 0, 16, 16));

            tsmiShadow.Checked = AnnotationOptions.Shadow;

            switch (shapeType)
            {
            default:
                tsddbShapeOptions.Visible = false;
                break;

            case ShapeType.RegionRectangle:
            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingFreehand:
            case ShapeType.DrawingLine:
            case ShapeType.DrawingArrow:
            case ShapeType.DrawingTextOutline:
            case ShapeType.DrawingTextBackground:
            case ShapeType.DrawingSpeechBalloon:
            case ShapeType.DrawingStep:
            case ShapeType.EffectBlur:
            case ShapeType.EffectPixelate:
                tsddbShapeOptions.Visible = true;
                break;
            }

            tsmiUndo.Enabled   = tsmiDeleteAll.Enabled = Shapes.Count > 0;
            tsmiDelete.Enabled = tsmiMoveTop.Enabled = tsmiMoveUp.Enabled = tsmiMoveDown.Enabled = tsmiMoveBottom.Enabled = CurrentShape != null;

            switch (shapeType)
            {
            default:
                tsbBorderColor.Visible   = false;
                tslnudBorderSize.Visible = false;
                tsmiShadow.Visible       = false;
                break;

            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingFreehand:
            case ShapeType.DrawingLine:
            case ShapeType.DrawingArrow:
            case ShapeType.DrawingTextOutline:
            case ShapeType.DrawingTextBackground:
            case ShapeType.DrawingSpeechBalloon:
            case ShapeType.DrawingStep:
                tsbBorderColor.Visible   = true;
                tslnudBorderSize.Visible = true;
                tsmiShadow.Visible       = true;
                break;
            }

            switch (shapeType)
            {
            default:
                tsbFillColor.Visible = false;
                break;

            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingTextBackground:
            case ShapeType.DrawingSpeechBalloon:
            case ShapeType.DrawingStep:
                tsbFillColor.Visible = true;
                break;
            }

            switch (shapeType)
            {
            default:
                tslnudCornerRadius.Visible = false;
                break;

            case ShapeType.RegionRectangle:
            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingTextBackground:
                tslnudCornerRadius.Visible = true;
                break;
            }

            tslnudBlurRadius.Visible   = shapeType == ShapeType.EffectBlur;
            tslnudPixelateSize.Visible = shapeType == ShapeType.EffectPixelate;
            tsbHighlightColor.Visible  = shapeType == ShapeType.EffectHighlight;

            if (tsmiRegionCapture != null)
            {
                tsmiRegionCapture.Visible = !Config.QuickCrop && ValidRegions.Length > 0;
            }
        }
Esempio n. 4
0
 private void DrawFPS(Graphics g, int offset)
 {
     ImageHelpers.DrawTextWithShadow(g, FPS.ToString(), new Point(offset, offset), infoFontBig, Brushes.White, Brushes.Black, new Point(0, 1));
 }
Esempio n. 5
0
        protected override void Draw(Graphics g)
        {
            borderDotPen2.DashOffset = (float)timer.Elapsed.TotalSeconds * 10;

            List <Rectangle> areas = AreaManager.GetValidAreas;

            if (areas.Count > 0 || !AreaManager.CurrentHoverArea.IsEmpty)
            {
                UpdateRegionPath();

                if (areas.Count > 0)
                {
                    using (Region region = new Region(regionDrawPath))
                    {
                        g.Clip = region;
                        g.FillRectangle(lightBackgroundBrush, ScreenRectangle0Based);
                        g.ResetClip();
                    }

                    g.DrawPath(borderPen, regionDrawPath);

                    if (areas.Count > 1)
                    {
                        Rectangle totalArea = AreaManager.CombineAreas();
                        g.DrawCrossRectangle(borderPen, totalArea, 15);

                        if (Config.ShowInfo)
                        {
                            ImageHelpers.DrawTextWithOutline(g, string.Format("X: {0} / Y: {1} / W: {2} / H: {3}", totalArea.X, totalArea.Y,
                                                                              totalArea.Width, totalArea.Height), new PointF(totalArea.X + 5, totalArea.Y - 25), textFont, Color.White, Color.Black);
                        }
                    }
                }

                if (AreaManager.IsCurrentHoverAreaValid)
                {
                    using (GraphicsPath hoverDrawPath = new GraphicsPath {
                        FillMode = FillMode.Winding
                    })
                    {
                        AddShapePath(hoverDrawPath, AreaManager.CurrentHoverArea.SizeOffset(-1));

                        g.DrawPath(borderDotPen, hoverDrawPath);
                        g.DrawPath(borderDotPen2, hoverDrawPath);
                    }
                }

                if (AreaManager.IsCurrentAreaValid)
                {
                    g.DrawRectangleProper(borderDotPen, AreaManager.CurrentArea);
                    g.DrawRectangleProper(borderDotPen2, AreaManager.CurrentArea);
                    DrawObjects(g);

                    if (RulerMode)
                    {
                        DrawRuler(g, AreaManager.CurrentArea, borderPen, 5, 10);
                        DrawRuler(g, AreaManager.CurrentArea, borderPen, 15, 100);

                        Point centerPos = new Point(AreaManager.CurrentArea.X + AreaManager.CurrentArea.Width / 2, AreaManager.CurrentArea.Y + AreaManager.CurrentArea.Height / 2);
                        int   markSize  = 10;
                        g.DrawLine(borderPen, centerPos.X, centerPos.Y - markSize, centerPos.X, centerPos.Y + markSize);
                        g.DrawLine(borderPen, centerPos.X - markSize, centerPos.Y, centerPos.X + markSize, centerPos.Y);
                    }
                }

                if (Config.ShowInfo)
                {
                    foreach (Rectangle area in areas)
                    {
                        if (area.IsValid())
                        {
                            string areaText;

                            if (RulerMode)
                            {
                                Point endPos = new Point(area.X + area.Width - 1, area.Y + area.Height - 1);
                                areaText = string.Format("X: {0} / Y: {1} / X2: {2} / Y2: {3}\nWidth: {4} px / Height: {5} px\nDistance: {6:0.00} px / Angle: {7:0.00}°", area.X, area.Y, endPos.X, endPos.Y,
                                                         area.Width, area.Height, MathHelpers.Distance(area.Location, endPos), MathHelpers.LookAtDegree(area.Location, endPos));
                                ImageHelpers.DrawTextWithOutline(g, areaText, new PointF(area.X + 15, area.Y + 15), textFont, Color.White, Color.Black);
                            }
                            else
                            {
                                areaText = string.Format("X: {0} / Y: {1}\nW: {2} / H: {3}", area.X, area.Y, area.Width, area.Height);
                                ImageHelpers.DrawTextWithOutline(g, areaText, new PointF(area.X + 5, area.Y + 5), textFont, Color.White, Color.Black);
                            }
                        }
                    }
                }
            }

            if (Config.ShowMagnifier)
            {
                DrawMagnifier(g);
            }

            if (Config.ShowCrosshair)
            {
                DrawCrosshair(g);
            }
        }
Esempio n. 6
0
 public IndexModel(HouseLemmingv3.Data.ApplicationDbContext context)
 {
     _context     = context;
     ImageHelpers = new ImageHelpers(context);
     UserManager  = _context.GetService <UserManager <ApplicationUser> >();
 }
Esempio n. 7
0
        private void UpdateContextMenu()
        {
            ShapeType shapeType = CurrentShapeType;

            tssObjectOptions.Visible   = tsmiDeleteAll.Visible = Shapes.Count > 0;
            tsmiDeleteSelected.Visible = CurrentShape != null;

            foreach (ToolStripMenuItem tsmi in cmsContextMenu.Items.OfType <ToolStripMenuItem>().Where(x => x.Tag is ShapeType))
            {
                if ((ShapeType)tsmi.Tag == shapeType)
                {
                    tsmi.RadioCheck();
                    break;
                }
            }

            Color borderColor;

            if (shapeType == ShapeType.DrawingText)
            {
                borderColor = AnnotationOptions.TextBorderColor;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                borderColor = AnnotationOptions.StepBorderColor;
            }
            else
            {
                borderColor = AnnotationOptions.BorderColor;
            }

            if (tsmiBorderColor.Image != null)
            {
                tsmiBorderColor.Image.Dispose();
            }
            tsmiBorderColor.Image = ImageHelpers.CreateColorPickerIcon(borderColor, new Rectangle(0, 0, 16, 16));

            int borderSize;

            if (shapeType == ShapeType.DrawingText)
            {
                borderSize = AnnotationOptions.TextBorderSize;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                borderSize = AnnotationOptions.StepBorderSize;
            }
            else
            {
                borderSize = AnnotationOptions.BorderSize;
            }

            tslnudBorderSize.Content.Value = borderSize;

            Color fillColor;

            if (shapeType == ShapeType.DrawingText)
            {
                fillColor = AnnotationOptions.TextFillColor;
            }
            else if (shapeType == ShapeType.DrawingStep)
            {
                fillColor = AnnotationOptions.StepFillColor;
            }
            else
            {
                fillColor = AnnotationOptions.FillColor;
            }

            if (tsmiFillColor.Image != null)
            {
                tsmiFillColor.Image.Dispose();
            }
            tsmiFillColor.Image = ImageHelpers.CreateColorPickerIcon(fillColor, new Rectangle(0, 0, 16, 16));

            tslnudRoundedRectangleRadius.Content.Value = AnnotationOptions.RoundedRectangleRadius;

            tslnudBlurRadius.Content.Value = AnnotationOptions.BlurRadius;

            tslnudPixelateSize.Content.Value = AnnotationOptions.PixelateSize;

            if (tsmiHighlightColor.Image != null)
            {
                tsmiHighlightColor.Image.Dispose();
            }
            tsmiHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.HighlightColor, new Rectangle(0, 0, 16, 16));

            switch (shapeType)
            {
            default:
                tssShapeOptions.Visible = false;
                break;

            case ShapeType.RegionRoundedRectangle:
            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingRoundedRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingLine:
            case ShapeType.DrawingArrow:
            case ShapeType.DrawingText:
            case ShapeType.DrawingStep:
            case ShapeType.DrawingBlur:
            case ShapeType.DrawingPixelate:
            case ShapeType.DrawingHighlight:
                tssShapeOptions.Visible = true;
                break;
            }

            switch (shapeType)
            {
            default:
                tsmiBorderColor.Visible  = false;
                tslnudBorderSize.Visible = false;
                break;

            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingRoundedRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingLine:
            case ShapeType.DrawingArrow:
            case ShapeType.DrawingText:
            case ShapeType.DrawingStep:
                tsmiBorderColor.Visible  = true;
                tslnudBorderSize.Visible = true;
                break;
            }

            switch (shapeType)
            {
            default:
                tsmiFillColor.Visible = false;
                break;

            case ShapeType.DrawingRectangle:
            case ShapeType.DrawingRoundedRectangle:
            case ShapeType.DrawingEllipse:
            case ShapeType.DrawingText:
            case ShapeType.DrawingStep:
                tsmiFillColor.Visible = true;
                break;
            }

            tslnudRoundedRectangleRadius.Visible = shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle;
            tslnudBlurRadius.Visible             = shapeType == ShapeType.DrawingBlur;
            tslnudPixelateSize.Visible           = shapeType == ShapeType.DrawingPixelate;
            tsmiHighlightColor.Visible           = shapeType == ShapeType.DrawingHighlight;
        }
Esempio n. 8
0
 public override Image Apply(Image img)
 {
     return(ImageHelpers.RoundedCorners(img, CornerRadius));
 }
Esempio n. 9
0
        private Image CombineImages()
        {
            if (images == null || images.Count == 0)
            {
                return(null);
            }

            if (images.Count == 1)
            {
                return((Image)images[0].Clone());
            }

            List <Image> output = new List <Image>();

            for (int i = 0; i < images.Count - Options.IgnoreLast; i++)
            {
                Image newImage;
                Image image = images[i];

                if (Options.TrimLeftEdge > 0 || Options.TrimTopEdge > 0 || Options.TrimTopEdge > 0 || Options.TrimBottomEdge > 0 ||
                    Options.CombineAdjustmentVertical > 0 || Options.CombineAdjustmentLastVertical > 0)
                {
                    Rectangle rect = new Rectangle(Options.TrimLeftEdge, Options.TrimTopEdge, image.Width - Options.TrimLeftEdge - Options.TrimRightEdge,
                                                   image.Height - Options.TrimTopEdge - Options.TrimBottomEdge);

                    if (i == images.Count - 1)
                    {
                        rect.Y      += Options.CombineAdjustmentLastVertical;
                        rect.Height -= Options.CombineAdjustmentLastVertical;
                    }
                    else if (i > 0)
                    {
                        rect.Y      += Options.CombineAdjustmentVertical;
                        rect.Height -= Options.CombineAdjustmentVertical;
                    }

                    newImage = ImageHelpers.CropImage(image, rect);

                    if (newImage == null)
                    {
                        continue;
                    }
                }
                else
                {
                    newImage = (Image)image.Clone();
                }

                output.Add(newImage);
            }

            Image result = ImageHelpers.CombineImages(output);

            foreach (Image image in output)
            {
                if (image != null)
                {
                    image.Dispose();
                }
            }

            output.Clear();

            return(result);
        }
Esempio n. 10
0
 public override Image Apply(Image img)
 {
     return(ImageHelpers.Pixelate((Bitmap)img, Size));
 }
Esempio n. 11
0
        private Image DrawWatermarkText(Image img, string drawText)
        {
            if (!string.IsNullOrEmpty(drawText) && Config.WatermarkFont.Size > 0)
            {
                Font  font            = null;
                Brush backgroundBrush = null;

                try
                {
                    int offset = Config.WatermarkOffset;

                    font = Config.WatermarkFont;
                    Size  textSize      = TextRenderer.MeasureText(drawText, font);
                    Size  labelSize     = new Size(textSize.Width + 10, textSize.Height + 10);
                    Point labelPosition = FindPosition(Config.WatermarkPositionMode, offset, img.Size, new Size(textSize.Width + 10, textSize.Height + 10), 1);

                    if (Config.WatermarkAutoHide && ((img.Width < labelSize.Width + offset) || (img.Height < labelSize.Height + offset)))
                    {
                        return(img);
                    }

                    Rectangle labelRectangle = new Rectangle(Point.Empty, labelSize);
                    Color     fontColor      = Config.WatermarkFontArgb;

                    using (Bitmap bmp = new Bitmap(labelRectangle.Width + 1, labelRectangle.Height + 1))
                        using (Graphics g = Graphics.FromImage(bmp))
                        {
                            g.SmoothingMode     = SmoothingMode.HighQuality;
                            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                            if (Config.WatermarkUseCustomGradient)
                            {
                                backgroundBrush = GradientMaker.CreateGradientBrush(labelRectangle.Size, Config.WatermarkGradient);
                            }
                            else
                            {
                                backgroundBrush = new LinearGradientBrush(labelRectangle, Config.WatermarkGradient1Argb, Config.WatermarkGradient2Argb, Config.WatermarkGradientType);
                            }

                            using (GraphicsPath gPath = new GraphicsPath())
                                using (Pen borderPen = new Pen(Config.WatermarkBorderArgb))
                                {
                                    gPath.AddRoundedRectangle(labelRectangle, Config.WatermarkCornerRadius);
                                    g.FillPath(backgroundBrush, gPath);
                                    g.DrawPath(borderPen, gPath);
                                }

                            using (Brush textBrush = new SolidBrush(fontColor))
                                using (StringFormat sf = new StringFormat {
                                    Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                                })
                                {
                                    g.DrawString(drawText, font, textBrush, bmp.Width / 2f, bmp.Height / 2f, sf);
                                }

                            using (Graphics gImg = Graphics.FromImage(img))
                            {
                                gImg.SmoothingMode = SmoothingMode.HighQuality;
                                gImg.DrawImage(bmp, labelPosition.X, labelPosition.Y, bmp.Width, bmp.Height);

                                if (Config.WatermarkAddReflection)
                                {
                                    using (Bitmap bmp2 = ImageHelpers.AddReflection(bmp, 50, 150, 10))
                                    {
                                        gImg.DrawImage(bmp2, new Rectangle(labelPosition.X, labelPosition.Y + bmp.Height - 1, bmp2.Width, bmp2.Height));
                                    }
                                }
                            }
                        }
                }
                catch (Exception ex)
                {
                    DebugHelper.WriteException(ex, "Error while drawing watermark");
                }
                finally
                {
                    if (font != null)
                    {
                        font.Dispose();
                    }
                    if (backgroundBrush != null)
                    {
                        backgroundBrush.Dispose();
                    }
                }
            }

            return(img);
        }
Esempio n. 12
0
        public TextDrawingInputBox(string text, TextDrawingOptions options, bool supportGradient, ColorPickerOptions colorPickerOptions)
        {
            InitializeComponent();
            ShareXResources.ApplyTheme(this);

            InputText          = text;
            Options            = options;
            ColorPickerOptions = colorPickerOptions;

            if (InputText != null)
            {
                txtInput.Text = InputText;
            }

            UpdateInputBox();

            cbFonts.Items.AddRange(FontFamily.Families.Select(x => x.Name).ToArray());

            if (cbFonts.Items.Contains(Options.Font))
            {
                cbFonts.SelectedItem = Options.Font;
            }
            else
            {
                cbFonts.SelectedItem = AnnotationOptions.DefaultFont;
            }

            nudTextSize.SetValue(Options.Size);

            btnTextColor.ColorPickerOptions = ColorPickerOptions;
            btnTextColor.Color = Options.Color;

            btnGradient.Visible = supportGradient;

            if (supportGradient)
            {
                tsmiEnableGradient.Checked = Options.Gradient;

                tsmiSecondColor.Image = ImageHelpers.CreateColorPickerIcon(Options.Color2, new Rectangle(0, 0, 16, 16));

                switch (Options.GradientMode)
                {
                case LinearGradientMode.Horizontal:
                    tsrbmiGradientHorizontal.Checked = true;
                    break;

                case LinearGradientMode.Vertical:
                    tsrbmiGradientVertical.Checked = true;
                    break;

                case LinearGradientMode.ForwardDiagonal:
                    tsrbmiGradientForwardDiagonal.Checked = true;
                    break;

                case LinearGradientMode.BackwardDiagonal:
                    tsrbmiGradientBackwardDiagonal.Checked = true;
                    break;
                }
            }

            cbBold.Checked      = Options.Bold;
            cbItalic.Checked    = Options.Italic;
            cbUnderline.Checked = Options.Underline;

            UpdateButtonImages();
            UpdateEnterTip();

            txtInput.SupportSelectAll();
        }
Esempio n. 13
0
        public ActionResult UploadPhoto(int id)
        {
            var v = SVD.Controller.Instance.VehicleController.GetVehicle(id);

            if (v == null)
            {
                return(Json(new { error = "Whoops, no such vehicle found." }));
            }

            var   result   = false;
            Image image    = null;
            var   filename = string.Empty;
            Photo photo    = null;

            #region resolve image between upload methods
            if (Request.Files != null && Request.Files.Count > 0)
            {
                // *** old-fashioned internet-explorer file-upload. ***
                var file = Request.Files[0];
                if (file != null)
                {
                    filename = Path.GetFileName(file.FileName);
                    if (Helpers.IsFileUploadValid(file.InputStream, file.FileName))
                    {
                        image  = Image.FromStream(file.InputStream);
                        result = true;
                    }
                }
            }
            else
            {
                // *** new-style raw upload. ***
                filename = Path.GetFileName(Request.Headers["X-File-Name"]);
                if (!string.IsNullOrEmpty(filename) && Helpers.IsFileUploadValid(Request.InputStream, filename))
                {
                    image  = Image.FromStream(Request.InputStream);
                    result = true;
                }
            }
            #endregion

            if (result)
            {
                // set a 1600px max image size.
                using (var highResImage = ImageHelpers.ResizeImage(image, 1600))
                {
                    var path = Helpers.SaveUploadedImage(highResImage, filename);
                    filename = Path.GetFileName(path);
                    photo    = v.AddPhoto(filename, PhotoType.HighResolution);
                    SVD.Controller.Instance.VehicleController.UpdateVehicle(v);
                }
            }

            var photoUrl = Helpers.DynamicImageUrl(photo, 207, true);

            if (image != null)
            {
                image.Dispose();
            }

            return(result ? Json(new { success = true, url = photoUrl, pid = photo.Id }) : Json(new { error = "whoops, something went wrong." }));
        }
Esempio n. 14
0
 public override Bitmap Apply(Bitmap bmp)
 {
     ImageHelpers.ColorDepth(bmp, BitsPerChannel);
     return(bmp);
 }
Esempio n. 15
0
 public override Image Apply(Image img)
 {
     return(ImageHelpers.TornEdges(img, Depth, Range, Sides, CurvedEdges));
 }
 private void DisplayCategoryImage()
 {
     CategoryPictureBox.Image = ImageHelpers.ByteArrayToImage(((Categories)CategoryListBox.SelectedItem).Picture);
 }
 /// <summary>
 /// Gets a value indicating whether the current request passes sanitizing rules.
 /// </summary>
 /// <param name="path">
 /// The image path.
 /// </param>
 /// <returns>
 /// <c>True</c> if the request is valid; otherwise, <c>False</c>.
 /// </returns>
 public bool IsValidRequest(string path)
 {
     return(ImageHelpers.IsValidImageExtension(path.Split('&', '?')[0]));
 }
Esempio n. 18
0
        protected override void Draw(Graphics g)
        {
            List <Rectangle> areas = AreaManager.GetValidAreas;

            if (areas.Count > 0 || !AreaManager.CurrentHoverArea.IsEmpty)
            {
                UpdateRegionPath();

                if (areas.Count > 0)
                {
                    if (Config.UseDimming)
                    {
                        using (Region region = new Region(regionDrawPath))
                        {
                            g.Clip = region;
                            g.FillRectangle(lightBackgroundBrush, ScreenRectangle0Based);
                            g.ResetClip();
                        }
                    }

                    g.DrawPath(borderPen, regionDrawPath);

                    if (areas.Count > 1)
                    {
                        Rectangle totalArea = AreaManager.CombineAreas();
                        g.DrawCrossRectangle(borderPen, totalArea, 15);

                        if (Config.ShowInfo)
                        {
                            ImageHelpers.DrawTextWithOutline(g, string.Format("X: {0} / Y: {1} / W: {2} / H: {3}", totalArea.X, totalArea.Y,
                                                                              totalArea.Width, totalArea.Height), new PointF(totalArea.X + 5, totalArea.Y - 25), textFont, Color.White, Color.Black);
                        }
                    }
                }

                if (AreaManager.IsCurrentHoverAreaValid)
                {
                    using (GraphicsPath hoverDrawPath = new GraphicsPath {
                        FillMode = FillMode.Winding
                    })
                    {
                        AddShapePath(hoverDrawPath, AreaManager.CurrentHoverArea.SizeOffset(-1));

                        g.DrawPath(borderPen, hoverDrawPath);
                        g.DrawPath(borderDotPen, hoverDrawPath);
                    }
                }

                if (AreaManager.IsCurrentAreaValid)
                {
                    g.DrawRectangleProper(borderPen, AreaManager.CurrentArea);
                    g.DrawRectangleProper(borderDotPen, AreaManager.CurrentArea);
                    DrawObjects(g);

                    if (RulerMode)
                    {
                        DrawRuler(g, AreaManager.CurrentArea, borderPen, 5, 10);
                        DrawRuler(g, AreaManager.CurrentArea, borderPen, 15, 100);

                        Point centerPos = new Point(AreaManager.CurrentArea.X + AreaManager.CurrentArea.Width / 2, AreaManager.CurrentArea.Y + AreaManager.CurrentArea.Height / 2);
                        int   markSize  = 10;
                        g.DrawLine(borderPen, centerPos.X, centerPos.Y - markSize, centerPos.X, centerPos.Y + markSize);
                        g.DrawLine(borderPen, centerPos.X - markSize, centerPos.Y, centerPos.X + markSize, centerPos.Y);
                    }
                }

                if (Config.ShowInfo)
                {
                    foreach (Rectangle area in areas)
                    {
                        if (area.IsValid())
                        {
                            if (RulerMode)
                            {
                                ImageHelpers.DrawTextWithOutline(g, GetRulerText(area), new PointF(area.X + 15, area.Y + 15), textFont, Color.White, Color.Black);
                            }
                            else
                            {
                                ImageHelpers.DrawTextWithOutline(g, GetAreaText(area), new PointF(area.X + 5, area.Y + 5), textFont, Color.White, Color.Black);
                            }
                        }
                    }
                }
            }

            if (OneClickMode)
            {
                DrawScreenColorPickerInfo(g);
            }

            if (Config.ShowMagnifier)
            {
                DrawMagnifier(g);
            }

            if (Config.ShowCrosshair)
            {
                DrawCrosshair(g);
            }
        }
Esempio n. 19
0
 public override Image Apply(Image img)
 {
     return(ImageHelpers.RotateImage(img, Angle, Upsize, Clip));
 }
Esempio n. 20
0
 public override void ApplyEffect(Bitmap bmp)
 {
     ImageHelpers.HighlightImage(bmp, HighlightColor);
 }
Esempio n. 21
0
        // Must be called before show form
        public void Prepare(Image img)
        {
            Image = img;

            if (Mode == RegionCaptureMode.Editor)
            {
                Rectangle rect = CaptureHelpers.GetActiveScreenBounds0Based();

                if (Image.Width > rect.Width || Image.Height > rect.Height)
                {
                    rect = ScreenRectangle0Based;
                }

                ImageRectangle = new Rectangle(rect.X + rect.Width / 2 - Image.Width / 2, rect.Y + rect.Height / 2 - Image.Height / 2, Image.Width, Image.Height);

                using (Image background = ImageHelpers.DrawCheckers(ScreenRectangle0Based.Width, ScreenRectangle0Based.Height))
                    using (Graphics g = Graphics.FromImage(background))
                    {
                        g.DrawImage(Image, ImageRectangle);

                        backgroundBrush = new TextureBrush(background)
                        {
                            WrapMode = WrapMode.Clamp
                        };
                    }
            }
            else if (Config.UseDimming)
            {
                using (Bitmap darkBackground = (Bitmap)Image.Clone())
                    using (Graphics g = Graphics.FromImage(darkBackground))
                        using (Brush brush = new SolidBrush(Color.FromArgb(30, Color.Black)))
                        {
                            g.FillRectangle(brush, 0, 0, darkBackground.Width, darkBackground.Height);

                            backgroundBrush = new TextureBrush(darkBackground)
                            {
                                WrapMode = WrapMode.Clamp
                            };
                        }

                backgroundHighlightBrush = new TextureBrush(Image)
                {
                    WrapMode = WrapMode.Clamp
                };
            }
            else
            {
                backgroundBrush = new TextureBrush(Image)
                {
                    WrapMode = WrapMode.Clamp
                };
            }

            ShapeManager = new ShapeManager(this);
            ShapeManager.WindowCaptureMode = Config.DetectWindows;
            ShapeManager.IncludeControls   = Config.DetectControls;

            if (Mode == RegionCaptureMode.OneClick || ShapeManager.WindowCaptureMode)
            {
                IntPtr handle = Handle;

                TaskEx.Run(() =>
                {
                    WindowsRectangleList wla = new WindowsRectangleList();
                    wla.IgnoreHandle         = handle;
                    wla.IncludeChildWindows  = ShapeManager.IncludeControls;
                    ShapeManager.Windows     = wla.GetWindowInfoListAsync(5000);
                });
            }

            if (Config.UseCustomInfoText || Mode == RegionCaptureMode.ScreenColorPicker)
            {
                bmpBackgroundImage = new Bitmap(Image);
            }
        }
Esempio n. 22
0
        public override Image Apply(Image img)
        {
            if (!string.IsNullOrEmpty(ImageLocation) && File.Exists(ImageLocation))
            {
                using (Image img2 = ImageHelpers.LoadImage(ImageLocation))
                {
                    // Calculate size first
                    Size imageSize = img2.Size;
                    if (SizeMode == DrawImageSizeMode.AbsoluteSize)
                    {
                        // Use Size property
                        imageSize = Size;
                    }
                    else if (SizeMode == DrawImageSizeMode.PercentageOfWatermark)
                    {
                        // Relative size (percentage of watermark)
                        imageSize = new Size((int)(img2.Width * (Size.Width / 100.0)), (int)(img2.Height * (Size.Height / 100.0)));
                    }
                    else if (SizeMode == DrawImageSizeMode.PercentageOfCanvas)
                    {
                        // Relative size (percentage of image)
                        imageSize = new Size((int)(img.Width * (Size.Width / 100.0)), (int)(img.Height * (Size.Height / 100.0)));
                    }

                    // Place the image
                    Point imagePosition;
                    if (RandomPosition)
                    {
                        int x = 0;
                        if (img.Width - imageSize.Width > 0)
                        {
                            x = MathHelpers.Random(0, img.Width - imageSize.Width);
                        }

                        int y = 0;
                        if (img.Height - imageSize.Height > 0)
                        {
                            y = MathHelpers.Random(0, img.Height - imageSize.Height);
                        }

                        imagePosition = new Point(x, y);
                    }
                    else
                    {
                        imagePosition = Helpers.GetPosition(Placement, Offset, img.Size, imageSize);
                    }

                    Rectangle imageRectangle = new Rectangle(imagePosition, imageSize);

                    if (AutoHide && !new Rectangle(0, 0, img.Width, img.Height).Contains(imageRectangle))
                    {
                        return(img);
                    }

                    using (Graphics g = Graphics.FromImage(img))
                    {
                        g.SetHighQuality();
                        g.DrawImage(img2, imageRectangle);
                    }
                }
            }

            return(img);
        }
Esempio n. 23
0
        public Image CaptureWindowTransparent(IntPtr handle)
        {
            if (handle.ToInt32() > 0)
            {
                Rectangle rect = CaptureHelpers.GetWindowRectangle(handle);

                if (CaptureShadow && !NativeMethods.IsZoomed(handle) && NativeMethods.IsDWMEnabled())
                {
                    rect.Inflate(ShadowOffset, ShadowOffset);
                    Rectangle intersectBounds = Screen.AllScreens.Select(x => x.Bounds).Where(x => x.IntersectsWith(rect)).Combine();
                    rect.Intersect(intersectBounds);
                }

                Bitmap     whiteBackground = null, blackBackground = null, whiteBackground2 = null;
                CursorData cursorData = null;
                bool       isTransparent = false, isTaskbarHide = false;

                try
                {
                    if (AutoHideTaskbar)
                    {
                        isTaskbarHide = NativeMethods.SetTaskbarVisibilityIfIntersect(false, rect);
                    }

                    if (CaptureCursor)
                    {
                        try
                        {
                            cursorData = new CursorData();
                        }
                        catch (Exception e)
                        {
                            DebugHelper.WriteException(e, "Cursor capture failed.");
                        }
                    }

                    using (Form form = new Form())
                    {
                        form.BackColor       = Color.White;
                        form.FormBorderStyle = FormBorderStyle.None;
                        form.ShowInTaskbar   = false;
                        form.StartPosition   = FormStartPosition.Manual;
                        form.Location        = new Point(rect.X, rect.Y);
                        form.Size            = new Size(rect.Width, rect.Height);

                        NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate);

                        if (!NativeMethods.SetWindowPos(form.Handle, handle, 0, 0, 0, 0,
                                                        SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE))
                        {
                            form.Close();
                            DebugHelper.WriteLine("Transparent capture failed. Reason: SetWindowPos fail.");
                            return(CaptureWindow(handle));
                        }

                        Thread.Sleep(10);
                        Application.DoEvents();

                        whiteBackground = CaptureRectangleNative(rect);

                        form.BackColor = Color.Black;
                        Application.DoEvents();

                        blackBackground = CaptureRectangleNative(rect);

                        form.BackColor = Color.White;
                        Application.DoEvents();

                        whiteBackground2 = CaptureRectangleNative(rect);

                        form.Close();
                    }

                    Bitmap transparentImage;

                    if (ImageHelpers.IsImagesEqual(whiteBackground, whiteBackground2))
                    {
                        transparentImage = CreateTransparentImage(whiteBackground, blackBackground);
                        isTransparent    = true;
                    }
                    else
                    {
                        DebugHelper.WriteLine("Transparent capture failed. Reason: Images not equal.");
                        transparentImage = whiteBackground2;
                    }

                    if (cursorData != null)
                    {
                        cursorData.DrawCursor(transparentImage, rect.Location);
                    }

                    if (isTransparent)
                    {
                        transparentImage = ImageHelpers.AutoCropImage(transparentImage);

                        if (!CaptureShadow)
                        {
                            TrimShadow(transparentImage);
                        }
                    }

                    return(transparentImage);
                }
                finally
                {
                    if (isTaskbarHide)
                    {
                        NativeMethods.SetTaskbarVisibility(true);
                    }

                    if (whiteBackground != null)
                    {
                        whiteBackground.Dispose();
                    }
                    if (blackBackground != null)
                    {
                        blackBackground.Dispose();
                    }
                    if (isTransparent && whiteBackground2 != null)
                    {
                        whiteBackground2.Dispose();
                    }
                }
            }

            return(null);
        }
Esempio n. 24
0
 public override Bitmap Apply(Bitmap bmp)
 {
     ImageHelpers.ReplaceColor(bmp, SourceColor, TargetColor, AutoSourceColor, Threshold);
     return(bmp);
 }
Esempio n. 25
0
 public override void ApplyEffect(Bitmap bmp)
 {
     ImageHelpers.BoxBlur(bmp, BlurRadius);
 }
Esempio n. 26
0
 public override Image Apply(Image img)
 {
     return(ImageHelpers.DrawReflection(img, Percentage, MaxAlpha, MinAlpha, Offset, Skew, SkewSize));
 }
Esempio n. 27
0
 public static Image AnnotateImageUsingGreenshot(Image img, string imgPath)
 {
     return(ImageHelpers.AnnotateImage(img, imgPath, !Program.Sandbox, Program.PersonalFolder,
                                       x => Program.MainForm.InvokeSafe(() => ClipboardHelpers.CopyImage(x)),
                                       x => Program.MainForm.InvokeSafe(() => UploadManager.UploadImage(x)),
                                       (x, filePath) => Program.MainForm.InvokeSafe(() => ImageHelpers.SaveImage(x, filePath)),
                                       (x, filePath) =>
     {
         string newFilePath = null;
         Program.MainForm.InvokeSafe(() => newFilePath = ImageHelpers.SaveImageFileDialog(x, filePath));
         return newFilePath;
     },
                                       x => Program.MainForm.InvokeSafe(() => PrintImage(x))));
 }
Esempio n. 28
0
 /// <summary>
 /// Gets a value indicating whether the current request passes sanitizing rules.
 /// </summary>
 /// <param name="path">
 /// The image path.
 /// </param>
 /// <returns>
 /// <c>True</c> if the request is valid; otherwise, <c>False</c>.
 /// </returns>
 public bool IsValidRequest(string path)
 {
     return(ImageHelpers.IsValidImageExtension(path));
 }
Esempio n. 29
0
 public override Image Apply(Image img)
 {
     return(ImageHelpers.AddShadow(img, Opacity, Size, Darkness + 1, Color, Offset));
 }
Esempio n. 30
0
        private void btnOpenImageFile_Click(object sender, EventArgs e)
        {
            string imageFilePath = ImageHelpers.OpenImageFileDialog(this);

            LoadImageFile(imageFilePath);
        }