mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-16 11:04:39 +12:00
Added border size & color options to "Pixelate" image effect
This commit is contained in:
parent
d491b1fc8a
commit
1c9783702a
|
@ -1360,6 +1360,29 @@ public static void Pixelate(Bitmap bmp, int pixelSize)
|
|||
}
|
||||
}
|
||||
|
||||
public static void Pixelate(Bitmap bmp, int pixelSize, int borderSize, Color borderColor)
|
||||
{
|
||||
Pixelate(bmp, pixelSize);
|
||||
|
||||
if (pixelSize > 1 && borderSize > 0 && borderColor.A > 0)
|
||||
{
|
||||
using (Bitmap bmpTexture = new Bitmap(pixelSize, pixelSize))
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(bmpTexture))
|
||||
using (Pen pen = new Pen(borderColor, borderSize) { Alignment = PenAlignment.Inset })
|
||||
{
|
||||
g.DrawRectangleProper(pen, new Rectangle(0, 0, bmpTexture.Width, bmpTexture.Height));
|
||||
}
|
||||
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
using (TextureBrush brush = new TextureBrush(bmpTexture))
|
||||
{
|
||||
g.FillRectangle(brush, 0, 0, bmp.Width, bmp.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ApplyBoxBlur(Bitmap bmp, int range)
|
||||
{
|
||||
BoxBlur(bmp, range, new Rectangle(0, 0, bmp.Width, bmp.Height));
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
using ShareX.HelpersLib;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Design;
|
||||
|
||||
namespace ShareX.ImageEffectsLib
|
||||
{
|
||||
|
@ -46,6 +47,24 @@ public int Size
|
|||
}
|
||||
}
|
||||
|
||||
private int borderSize;
|
||||
|
||||
[DefaultValue(0)]
|
||||
public int BorderSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return borderSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
borderSize = value.Max(0);
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue(typeof(Color), "Black"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
|
||||
public Color BorderColor { get; set; }
|
||||
|
||||
public Pixelate()
|
||||
{
|
||||
this.ApplyDefaultPropertyValues();
|
||||
|
@ -53,7 +72,7 @@ public Pixelate()
|
|||
|
||||
public override Bitmap Apply(Bitmap bmp)
|
||||
{
|
||||
ImageHelpers.Pixelate(bmp, Size);
|
||||
ImageHelpers.Pixelate(bmp, Size, BorderSize, BorderColor);
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue