Add option to set background color for CutOut tool

This commit is contained in:
Michael Bray 2024-04-12 06:05:11 -04:00
parent cbad9a45e4
commit 2368639f31
8 changed files with 58 additions and 15 deletions

View File

@ -260,24 +260,24 @@ namespace ShareX.HelpersLib
return null;
}
private static Bitmap ApplyCutOutEffect(Bitmap bmp, AnchorStyles effectEdge, CutOutEffectType effectType, int effectSize)
private static Bitmap ApplyCutOutEffect(Bitmap bmp, AnchorStyles effectEdge, CutOutEffectType effectType, int effectSize, Color cutOutBackgroundColor)
{
switch (effectType)
{
case CutOutEffectType.None:
return bmp;
case CutOutEffectType.ZigZag:
return TornEdges(bmp, effectSize, effectSize, effectEdge, false, false);
return TornEdges(bmp, effectSize, effectSize, effectEdge, false, false, cutOutBackgroundColor);
case CutOutEffectType.TornEdge:
return TornEdges(bmp, effectSize, effectSize * 2, effectEdge, false, true);
return TornEdges(bmp, effectSize, effectSize * 2, effectEdge, false, true, cutOutBackgroundColor);
case CutOutEffectType.Wave:
return WavyEdges(bmp, effectSize, effectSize * 5, effectEdge);
return WavyEdges(bmp, effectSize, effectSize * 5, effectEdge, cutOutBackgroundColor);
}
throw new NotImplementedException();
}
public static Bitmap CutOutBitmapMiddle(Bitmap bmp, Orientation orientation, int start, int size, CutOutEffectType effectType, int effectSize)
public static Bitmap CutOutBitmapMiddle(Bitmap bmp, Orientation orientation, int start, int size, CutOutEffectType effectType, int effectSize, Color cutOutBackgroundColor)
{
if (bmp != null && size > 0)
{
@ -290,7 +290,7 @@ namespace ShareX.HelpersLib
: new Rectangle(0, 0, bmp.Width, Math.Min(start, bmp.Height));
firstPart = CropBitmap(bmp, r);
AnchorStyles effectEdge = orientation == Orientation.Horizontal ? AnchorStyles.Right : AnchorStyles.Bottom;
firstPart = ApplyCutOutEffect(firstPart, effectEdge, effectType, effectSize);
firstPart = ApplyCutOutEffect(firstPart, effectEdge, effectType, effectSize, cutOutBackgroundColor);
}
int cutDimension = orientation == Orientation.Horizontal ? bmp.Width : bmp.Height;
@ -302,7 +302,7 @@ namespace ShareX.HelpersLib
: new Rectangle(0, end, bmp.Width, bmp.Height - end);
secondPart = CropBitmap(bmp, r);
AnchorStyles effectEdge = orientation == Orientation.Horizontal ? AnchorStyles.Left : AnchorStyles.Top;
secondPart = ApplyCutOutEffect(secondPart, effectEdge, effectType, effectSize);
secondPart = ApplyCutOutEffect(secondPart, effectEdge, effectType, effectSize, cutOutBackgroundColor);
}
if (firstPart != null && secondPart != null)
@ -1844,7 +1844,7 @@ namespace ShareX.HelpersLib
}
}
public static Bitmap WavyEdges(Bitmap bmp, int waveDepth, int waveRange, AnchorStyles sides)
public static Bitmap WavyEdges(Bitmap bmp, int waveDepth, int waveRange, AnchorStyles sides, Color cutOutBackgroundColor)
{
if (waveDepth < 1 || waveRange < 1 || sides == AnchorStyles.None)
{
@ -1934,12 +1934,13 @@ namespace ShareX.HelpersLib
{
g.SetHighQuality();
g.PixelOffsetMode = PixelOffsetMode.Half;
g.Clear(cutOutBackgroundColor);
g.FillPolygon(brush, points.ToArray());
}
return bmpResult;
}
public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorStyles sides, bool curvedEdges, bool random)
public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorStyles sides, bool curvedEdges, bool random, Color cutOutBackgroundColor)
{
if (tornDepth < 1 || tornRange < 1 || sides == AnchorStyles.None)
{
@ -2028,6 +2029,7 @@ namespace ShareX.HelpersLib
{
g.SetHighQuality();
g.PixelOffsetMode = PixelOffsetMode.Half;
g.Clear(cutOutBackgroundColor);
Point[] fillPoints = points.Distinct().ToArray();

View File

@ -26,6 +26,7 @@
using ShareX.HelpersLib;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
namespace ShareX.ImageEffectsLib
@ -45,6 +46,9 @@ namespace ShareX.ImageEffectsLib
[DefaultValue(true)]
public bool CurvedEdges { get; set; }
[DefaultValue(typeof(Color), "Transparent"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
public Color CutOutBackgroundColor { get; set; }
public TornEdge()
{
this.ApplyDefaultPropertyValues();
@ -52,7 +56,7 @@ namespace ShareX.ImageEffectsLib
public override Bitmap Apply(Bitmap bmp)
{
return ImageHelpers.TornEdges(bmp, Depth, Range, Sides, CurvedEdges, true);
return ImageHelpers.TornEdges(bmp, Depth, Range, Sides, CurvedEdges, true, this.CutOutBackgroundColor);
}
protected override string GetSummary()

View File

@ -26,6 +26,7 @@
using ShareX.HelpersLib;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
namespace ShareX.ImageEffectsLib
@ -47,9 +48,12 @@ namespace ShareX.ImageEffectsLib
this.ApplyDefaultPropertyValues();
}
[DefaultValue(typeof(Color), "Transparent"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
public Color CutOutBackgroundColor { get; set; }
public override Bitmap Apply(Bitmap bmp)
{
return ImageHelpers.WavyEdges(bmp, Depth, Range, Sides);
return ImageHelpers.WavyEdges(bmp, Depth, Range, Sides, this.CutOutBackgroundColor);
}
protected override string GetSummary()

View File

@ -323,6 +323,15 @@ namespace ShareX.ScreenCaptureLib.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Cut out background color.
/// </summary>
internal static string CutOutBackgroundColor {
get {
return ResourceManager.GetString("CutOutBackgroundColor", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cut out effect size:.
/// </summary>

View File

@ -830,4 +830,7 @@ Would you like to save the changes before closing the image editor?</value>
<data name="control_record_green" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\control-record-green.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="CutOutBackgroundColor" xml:space="preserve">
<value>Cut out background color</value>
</data>
</root>

View File

@ -47,6 +47,7 @@ namespace ShareX.ScreenCaptureLib
public int DrawingCornerRadius { get; set; } = 3;
public bool Shadow { get; set; } = true;
public Color ShadowColor { get; set; } = Color.FromArgb(125, 0, 0, 0);
public Color CutOutBackgroundColor { get; set; } = Color.Transparent;
public Point ShadowOffset { get; set; } = new Point(0, 1);
// Line, arrow drawing

View File

@ -1993,12 +1993,12 @@ namespace ShareX.ScreenCaptureLib
if (isHorizontal && cropRect.Width > 0)
{
CollapseAllHorizontal(rect.X, rect.Width);
UpdateCanvas(ImageHelpers.CutOutBitmapMiddle(Form.Canvas, Orientation.Horizontal, cropRect.X, cropRect.Width, AnnotationOptions.CutOutEffectType, AnnotationOptions.CutOutEffectSize));
UpdateCanvas(ImageHelpers.CutOutBitmapMiddle(Form.Canvas, Orientation.Horizontal, cropRect.X, cropRect.Width, AnnotationOptions.CutOutEffectType, AnnotationOptions.CutOutEffectSize, AnnotationOptions.CutOutBackgroundColor));
}
else if (!isHorizontal && cropRect.Height > 0)
{
CollapseAllVertical(rect.Y, rect.Height);
UpdateCanvas(ImageHelpers.CutOutBitmapMiddle(Form.Canvas, Orientation.Vertical, cropRect.Y, cropRect.Height, AnnotationOptions.CutOutEffectType, AnnotationOptions.CutOutEffectSize));
UpdateCanvas(ImageHelpers.CutOutBitmapMiddle(Form.Canvas, Orientation.Vertical, cropRect.Y, cropRect.Height, AnnotationOptions.CutOutEffectType, AnnotationOptions.CutOutEffectSize, AnnotationOptions.CutOutBackgroundColor));
}
}

View File

@ -49,7 +49,7 @@ namespace ShareX.ScreenCaptureLib
private ToolStripButton tsbSaveImage, tsbBorderColor, tsbFillColor, tsbHighlightColor;
private ToolStripDropDownButton tsddbShapeOptions;
private ToolStripMenuItem tsmiShadow, tsmiShadowColor, tsmiUndo, tsmiRedo, tsmiDuplicate, tsmiDelete, tsmiDeleteAll,
tsmiMoveTop, tsmiMoveUp, tsmiMoveDown, tsmiMoveBottom, tsmiRegionCapture, tsmiQuickCrop, tsmiShowMagnifier;
tsmiMoveTop, tsmiMoveUp, tsmiMoveDown, tsmiMoveBottom, tsmiRegionCapture, tsmiQuickCrop, tsmiShowMagnifier, tsmiCutoutBackgroundColor;
private ToolStripLabeledNumericUpDown tslnudBorderSize, tslnudCornerRadius, tslnudCenterPoints, tslnudBlurRadius, tslnudPixelateSize, tslnudStepFontSize,
tslnudMagnifierPixelCount, tslnudStartingStepValue, tslnudMagnifyStrength, tslnudCutOutEffectSize;
private ToolStripLabel tslDragLeft, tslDragRight;
@ -668,6 +668,22 @@ namespace ShareX.ScreenCaptureLib
};
tsddbShapeOptions.DropDownItems.Add(tslnudCutOutEffectSize);
tsmiCutoutBackgroundColor = new ToolStripMenuItem(Resources.CutOutBackgroundColor);
tsmiCutoutBackgroundColor.Click += (sender, e) =>
{
Form.Pause();
if (PickColor(AnnotationOptions.CutOutBackgroundColor, out Color newColor))
{
AnnotationOptions.CutOutBackgroundColor = newColor;
UpdateMenu();
UpdateCurrentShape();
}
Form.Resume();
};
tsddbShapeOptions.DropDownItems.Add(tsmiCutoutBackgroundColor);
// In dropdown menu if only last item is visible then menu opens at 0, 0 position on first open, so need to add dummy item to solve this weird bug...
tsddbShapeOptions.DropDownItems.Add(new ToolStripSeparator() { Visible = false });
@ -1492,6 +1508,9 @@ namespace ShareX.ScreenCaptureLib
tslnudCutOutEffectSize.Content.Value = AnnotationOptions.CutOutEffectSize;
if (tsmiCutoutBackgroundColor.Image != null) tsmiCutoutBackgroundColor.Image.Dispose();
tsmiCutoutBackgroundColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.CutOutBackgroundColor, new Rectangle(0, 0, 16, 16));
switch (shapeType)
{
default:
@ -1546,7 +1565,6 @@ namespace ShareX.ScreenCaptureLib
tsbBorderColor.Visible = true;
tslnudBorderSize.Visible = true;
tsmiShadow.Visible = true;
tsmiShadowColor.Visible = true;
break;
}
@ -1605,6 +1623,7 @@ namespace ShareX.ScreenCaptureLib
tsbHighlightColor.Visible = shapeType == ShapeType.EffectHighlight;
tscbCutOutEffectType.Visible = shapeType == ShapeType.ToolCutOut;
tslnudCutOutEffectSize.Visible = shapeType == ShapeType.ToolCutOut;
tsmiCutoutBackgroundColor.Visible = shapeType == ShapeType.ToolCutOut;
if (tsmiRegionCapture != null)
{
@ -1628,4 +1647,5 @@ namespace ShareX.ScreenCaptureLib
MenuTextAnimation.Start();
}
}
}
}