Proof of concept Torn Edges effect on cut

This commit is contained in:
Niels Martin Hansen 2022-08-16 23:46:00 +02:00
parent 32cae726e8
commit ac0cfcd4ec
3 changed files with 69 additions and 4 deletions

View file

@ -212,4 +212,13 @@ public enum StepType // Localized
RomanNumeralsUppercase,
RomanNumeralsLowercase
}
public enum CutOutEffectType // Localized (probably)
{
None,
ZigZag,
TornEdge,
Wave,
Gradient
}
}

View file

@ -223,7 +223,7 @@ public static Bitmap CropBitmap(Bitmap bmp, Rectangle rect)
return null;
}
public static Bitmap CutOutBitmapMiddleHorizontal(Bitmap bmp, int x, int width)
public static Bitmap CutOutBitmapMiddleHorizontal(Bitmap bmp, int x, int width, CutOutEffectType effectType, int effectSize)
{
if (bmp != null && width > 0)
{
@ -231,11 +231,39 @@ public static Bitmap CutOutBitmapMiddleHorizontal(Bitmap bmp, int x, int width)
if (x > 0)
{
leftPart = CropBitmap(bmp, new Rectangle(0, 0, Math.Min(x, bmp.Width), bmp.Height));
switch (effectType)
{
case CutOutEffectType.None:
break;
case CutOutEffectType.ZigZag:
break;
case CutOutEffectType.TornEdge:
leftPart = TornEdges(leftPart, effectSize, effectSize * 2, AnchorStyles.Right, false);
break;
case CutOutEffectType.Wave:
break;
case CutOutEffectType.Gradient:
break;
}
}
if (x + width < bmp.Width)
{
int x2 = Math.Max(x + width, 0);
rightPart = CropBitmap(bmp, new Rectangle(x2, 0, bmp.Width - x2, bmp.Height));
switch (effectType)
{
case CutOutEffectType.None:
break;
case CutOutEffectType.ZigZag:
break;
case CutOutEffectType.TornEdge:
rightPart = TornEdges(rightPart, effectSize, effectSize * 2, AnchorStyles.Left, false);
break;
case CutOutEffectType.Wave:
break;
case CutOutEffectType.Gradient:
break;
}
}
if (leftPart != null && rightPart != null)
@ -255,7 +283,7 @@ public static Bitmap CutOutBitmapMiddleHorizontal(Bitmap bmp, int x, int width)
return null;
}
public static Bitmap CutOutBitmapMiddleVertical(Bitmap bmp, int y, int height)
public static Bitmap CutOutBitmapMiddleVertical(Bitmap bmp, int y, int height, CutOutEffectType effectType, int effectSize)
{
if (bmp != null && height > 0)
{
@ -263,11 +291,39 @@ public static Bitmap CutOutBitmapMiddleVertical(Bitmap bmp, int y, int height)
if (y > 0)
{
topPart = CropBitmap(bmp, new Rectangle(0, 0, bmp.Width, Math.Min(y, bmp.Height)));
switch (effectType)
{
case CutOutEffectType.None:
break;
case CutOutEffectType.ZigZag:
break;
case CutOutEffectType.TornEdge:
topPart = TornEdges(topPart, effectSize, effectSize * 2, AnchorStyles.Bottom, false);
break;
case CutOutEffectType.Wave:
break;
case CutOutEffectType.Gradient:
break;
}
}
if (y + height < bmp.Height)
{
int y2 = Math.Max(y + height, 0);
bottomPart = CropBitmap(bmp, new Rectangle(0, y2, bmp.Width, bmp.Height - y2));
switch (effectType)
{
case CutOutEffectType.None:
break;
case CutOutEffectType.ZigZag:
break;
case CutOutEffectType.TornEdge:
bottomPart = TornEdges(bottomPart, effectSize, effectSize * 2, AnchorStyles.Top, false);
break;
case CutOutEffectType.Wave:
break;
case CutOutEffectType.Gradient:
break;
}
}
if (topPart != null && bottomPart != null)

View file

@ -1931,12 +1931,12 @@ public void CutOut(RectangleF rect)
if (isHorizontal && cropRect.Width > 0)
{
CollapseAllHorizontal(rect.X, rect.Width);
UpdateCanvas(ImageHelpers.CutOutBitmapMiddleHorizontal(Form.Canvas, cropRect.X, cropRect.Width));
UpdateCanvas(ImageHelpers.CutOutBitmapMiddleHorizontal(Form.Canvas, cropRect.X, cropRect.Width, CutOutEffectType.TornEdge, 5));
}
else if (!isHorizontal && cropRect.Height > 0)
{
CollapseAllVertical(rect.Y, rect.Height);
UpdateCanvas(ImageHelpers.CutOutBitmapMiddleVertical(Form.Canvas, cropRect.Y, cropRect.Height));
UpdateCanvas(ImageHelpers.CutOutBitmapMiddleVertical(Form.Canvas, cropRect.Y, cropRect.Height, CutOutEffectType.TornEdge, 5));
}
}