mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Improvements to async effect processing
This commit is contained in:
parent
7df6f6c4f5
commit
7f90c61a9d
3 changed files with 14 additions and 30 deletions
|
@ -62,7 +62,7 @@ public void WriteElapsedSeconds(string text = null)
|
|||
|
||||
public void WriteElapsedMilliseconds(string text = null)
|
||||
{
|
||||
Write(text, timer.ElapsedMilliseconds + " milliseconds.");
|
||||
Write(text, timer.Elapsed.TotalMilliseconds + " milliseconds.");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -35,7 +35,6 @@ public abstract class BaseEffectShape : BaseShape
|
|||
|
||||
public abstract string OverlayText { get; }
|
||||
|
||||
private Image canvasCopy;
|
||||
private bool isEffectCaching;
|
||||
private Image cachedEffect;
|
||||
|
||||
|
@ -131,32 +130,27 @@ private void CacheEffect()
|
|||
{
|
||||
if (!isEffectCaching)
|
||||
{
|
||||
isEffectCaching = true;
|
||||
|
||||
if (canvasCopy == null)
|
||||
{
|
||||
canvasCopy = (Image)Manager.Form.Canvas.Clone();
|
||||
}
|
||||
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
ClearCache();
|
||||
ClearCache(true);
|
||||
|
||||
if (IsInsideCanvas)
|
||||
{
|
||||
cachedEffect = Manager.CropImage(canvasCopy, RectangleInsideCanvas);
|
||||
isEffectCaching = true;
|
||||
|
||||
cachedEffect = Manager.CropImage(RectangleInsideCanvas);
|
||||
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
ApplyEffect((Bitmap)cachedEffect);
|
||||
}
|
||||
|
||||
isEffectCaching = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearCache()
|
||||
private void ClearCache(bool forceClear = false)
|
||||
{
|
||||
if (cachedEffect != null)
|
||||
if ((forceClear || !isEffectCaching) && cachedEffect != null)
|
||||
{
|
||||
cachedEffect.Dispose();
|
||||
cachedEffect = null;
|
||||
|
@ -166,11 +160,6 @@ private void ClearCache()
|
|||
public override void Dispose()
|
||||
{
|
||||
ClearCache();
|
||||
|
||||
if (canvasCopy != null)
|
||||
{
|
||||
canvasCopy.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1332,11 +1332,6 @@ public void CropArea(Rectangle rect)
|
|||
}
|
||||
|
||||
public Image CropImage(Rectangle rect, bool onlyIfSizeDifferent = false)
|
||||
{
|
||||
return CropImage(Form.Canvas, rect, onlyIfSizeDifferent);
|
||||
}
|
||||
|
||||
public Image CropImage(Image img, Rectangle rect, bool onlyIfSizeDifferent = false)
|
||||
{
|
||||
rect = CaptureHelpers.ScreenToClient(rect);
|
||||
|
||||
|
@ -1345,11 +1340,11 @@ public Image CropImage(Image img, Rectangle rect, bool onlyIfSizeDifferent = fal
|
|||
rect.X -= offset.X;
|
||||
rect.Y -= offset.Y;
|
||||
|
||||
rect.Intersect(new Rectangle(0, 0, img.Width, img.Height));
|
||||
rect.Intersect(new Rectangle(0, 0, Form.Canvas.Width, Form.Canvas.Height));
|
||||
|
||||
if (rect.IsValid() && (!onlyIfSizeDifferent || rect.Size != img.Size))
|
||||
if (rect.IsValid() && (!onlyIfSizeDifferent || rect.Size != Form.Canvas.Size))
|
||||
{
|
||||
return ImageHelpers.CropImage(img, rect);
|
||||
return ImageHelpers.CropBitmap((Bitmap)Form.Canvas, rect);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue