mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 01:37:31 +13:00
Added real time blur, pixelate, highlight preview in image editor
This commit is contained in:
parent
5409315390
commit
100cc47585
6 changed files with 113 additions and 44 deletions
|
@ -149,9 +149,11 @@ public virtual void OnCreating()
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void OnCreated()
|
||||
{
|
||||
}
|
||||
public virtual void OnCreated() { }
|
||||
|
||||
public virtual void OnMoving() { }
|
||||
|
||||
public virtual void OnMoved() { }
|
||||
|
||||
public virtual void OnUpdate()
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib
|
||||
{
|
||||
|
@ -31,11 +32,60 @@ public abstract class BaseEffectShape : BaseShape
|
|||
{
|
||||
public override ShapeCategory ShapeCategory { get; } = ShapeCategory.Effect;
|
||||
|
||||
public abstract void OnDraw(Graphics g);
|
||||
private Image cachedEffect;
|
||||
|
||||
public abstract void ApplyEffect(Bitmap bmp);
|
||||
|
||||
public virtual void OnDraw(Graphics g)
|
||||
{
|
||||
if (cachedEffect != null)
|
||||
{
|
||||
g.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||
g.DrawImage(cachedEffect, Rectangle);
|
||||
g.InterpolationMode = InterpolationMode.Bilinear;
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDrawOverlay(g);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void OnDrawOverlay(Graphics g);
|
||||
|
||||
public virtual void OnDrawFinal(Graphics g, Bitmap bmp)
|
||||
{
|
||||
OnDraw(g);
|
||||
}
|
||||
|
||||
public override void OnCreated()
|
||||
{
|
||||
CacheEffect();
|
||||
}
|
||||
|
||||
public override void OnMoving()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public override void OnMoved()
|
||||
{
|
||||
CacheEffect();
|
||||
}
|
||||
|
||||
private void CacheEffect()
|
||||
{
|
||||
Dispose();
|
||||
cachedEffect = Manager.CropImage(Rectangle);
|
||||
ApplyEffect((Bitmap)cachedEffect);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (cachedEffect != null)
|
||||
{
|
||||
cachedEffect.Dispose();
|
||||
cachedEffect = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,28 +44,30 @@ public override void OnConfigSave()
|
|||
AnnotationOptions.BlurRadius = BlurRadius;
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
public override void ApplyEffect(Bitmap bmp)
|
||||
{
|
||||
if (BlurRadius > 1)
|
||||
ImageHelpers.BoxBlur(bmp, BlurRadius);
|
||||
}
|
||||
|
||||
public override void OnDrawOverlay(Graphics g)
|
||||
{
|
||||
using (Brush brush = new SolidBrush(Color.FromArgb(150, Color.Black)))
|
||||
{
|
||||
using (Brush brush = new SolidBrush(Color.FromArgb(150, Color.Black)))
|
||||
g.FillRectangle(brush, Rectangle);
|
||||
}
|
||||
|
||||
g.DrawCornerLines(Rectangle.Offset(1), Pens.White, 20);
|
||||
|
||||
using (Font font = new Font("Verdana", 12))
|
||||
{
|
||||
string text = $"Blur ({BlurRadius})";
|
||||
Size textSize = g.MeasureString(text, font).ToSize();
|
||||
|
||||
if (Rectangle.Width > textSize.Width && Rectangle.Height > textSize.Height)
|
||||
{
|
||||
g.FillRectangle(brush, Rectangle);
|
||||
}
|
||||
|
||||
g.DrawCornerLines(Rectangle.Offset(1), Pens.White, 20);
|
||||
|
||||
using (Font font = new Font("Verdana", 12))
|
||||
{
|
||||
string text = $"Blur ({BlurRadius})";
|
||||
Size textSize = g.MeasureString(text, font).ToSize();
|
||||
|
||||
if (Rectangle.Width > textSize.Width && Rectangle.Height > textSize.Height)
|
||||
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
|
||||
{
|
||||
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
|
||||
{
|
||||
g.DrawString(text, font, Brushes.White, Rectangle, sf);
|
||||
}
|
||||
g.DrawString(text, font, Brushes.White, Rectangle, sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +82,7 @@ public override void OnDrawFinal(Graphics g, Bitmap bmp)
|
|||
|
||||
using (Bitmap croppedImage = ImageHelpers.CropBitmap(bmp, rect))
|
||||
{
|
||||
ImageHelpers.BoxBlur(croppedImage, BlurRadius);
|
||||
ApplyEffect(croppedImage);
|
||||
|
||||
g.DrawImage(croppedImage, rect);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,12 @@ public override void OnConfigSave()
|
|||
AnnotationOptions.HighlightColor = HighlightColor;
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
public override void ApplyEffect(Bitmap bmp)
|
||||
{
|
||||
ImageHelpers.HighlightImage(bmp, HighlightColor);
|
||||
}
|
||||
|
||||
public override void OnDrawOverlay(Graphics g)
|
||||
{
|
||||
using (Brush brush = new SolidBrush(Color.FromArgb(100, HighlightColor)))
|
||||
{
|
||||
|
@ -75,7 +80,7 @@ public override void OnDrawFinal(Graphics g, Bitmap bmp)
|
|||
|
||||
using (Bitmap croppedImage = ImageHelpers.CropBitmap(bmp, rect))
|
||||
{
|
||||
ImageHelpers.HighlightImage(croppedImage, HighlightColor);
|
||||
ApplyEffect(croppedImage);
|
||||
|
||||
g.DrawImage(croppedImage, rect);
|
||||
}
|
||||
|
|
|
@ -44,28 +44,30 @@ public override void OnConfigSave()
|
|||
AnnotationOptions.PixelateSize = PixelSize;
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
public override void ApplyEffect(Bitmap bmp)
|
||||
{
|
||||
if (PixelSize > 1)
|
||||
ImageHelpers.Pixelate(bmp, PixelSize);
|
||||
}
|
||||
|
||||
public override void OnDrawOverlay(Graphics g)
|
||||
{
|
||||
using (Brush brush = new SolidBrush(Color.FromArgb(150, Color.Black)))
|
||||
{
|
||||
using (Brush brush = new SolidBrush(Color.FromArgb(150, Color.Black)))
|
||||
g.FillRectangle(brush, Rectangle);
|
||||
}
|
||||
|
||||
g.DrawCornerLines(Rectangle.Offset(1), Pens.White, 20);
|
||||
|
||||
using (Font font = new Font("Verdana", 12))
|
||||
{
|
||||
string text = $"Pixelate ({PixelSize})";
|
||||
Size textSize = g.MeasureString(text, font).ToSize();
|
||||
|
||||
if (Rectangle.Width > textSize.Width && Rectangle.Height > textSize.Height)
|
||||
{
|
||||
g.FillRectangle(brush, Rectangle);
|
||||
}
|
||||
|
||||
g.DrawCornerLines(Rectangle.Offset(1), Pens.White, 20);
|
||||
|
||||
using (Font font = new Font("Verdana", 12))
|
||||
{
|
||||
string text = $"Pixelate ({PixelSize})";
|
||||
Size textSize = g.MeasureString(text, font).ToSize();
|
||||
|
||||
if (Rectangle.Width > textSize.Width && Rectangle.Height > textSize.Height)
|
||||
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
|
||||
{
|
||||
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
|
||||
{
|
||||
g.DrawString(text, font, Brushes.White, Rectangle, sf);
|
||||
}
|
||||
g.DrawString(text, font, Brushes.White, Rectangle, sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +82,7 @@ public override void OnDrawFinal(Graphics g, Bitmap bmp)
|
|||
|
||||
using (Bitmap croppedImage = ImageHelpers.CropBitmap(bmp, rect))
|
||||
{
|
||||
ImageHelpers.Pixelate(croppedImage, PixelSize);
|
||||
ApplyEffect(croppedImage);
|
||||
|
||||
g.DrawImage(croppedImage, rect);
|
||||
}
|
||||
|
|
|
@ -434,7 +434,9 @@ private void form_KeyDown(object sender, KeyEventArgs e)
|
|||
case Keys.F1:
|
||||
Options.ShowHotkeys = !Options.ShowHotkeys;
|
||||
if (tsmiTips != null)
|
||||
{
|
||||
tsmiTips.Checked = Options.ShowHotkeys;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -672,6 +674,7 @@ private void StartRegionSelection()
|
|||
if (shape != null && shape.ShapeType == CurrentTool) // Select shape
|
||||
{
|
||||
IsMoving = true;
|
||||
shape.OnMoving();
|
||||
Form.Cursor = Cursors.SizeAll;
|
||||
CurrentShape = shape;
|
||||
SelectCurrentShape();
|
||||
|
@ -688,6 +691,7 @@ private void StartRegionSelection()
|
|||
private void EndRegionSelection()
|
||||
{
|
||||
bool wasCreating = IsCreating;
|
||||
bool wasMoving = IsMoving;
|
||||
|
||||
IsCreating = false;
|
||||
IsMoving = false;
|
||||
|
@ -729,6 +733,10 @@ private void EndRegionSelection()
|
|||
|
||||
OnShapeCreated(shape);
|
||||
}
|
||||
else if (wasMoving)
|
||||
{
|
||||
shape.OnMoved();
|
||||
}
|
||||
|
||||
SelectCurrentShape();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue