diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index 3709aadd8..1c3787051 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -521,7 +521,20 @@ namespace Greenshot.Drawing { } return false; } - + + public void ApplyBitmapEffect() { + Rectangle cropRectangle = new Rectangle(Point.Empty, Image.Size); + Bitmap tmpImage = ((Bitmap)Image).Clone(cropRectangle, Image.PixelFormat); + tmpImage.SetResolution(Image.HorizontalResolution, Image.VerticalResolution); + + // Currently only one effect exists, others could follow + ImageHelper.ApplyTornEdge(tmpImage); + + // Make undoable + MakeUndoable(new SurfaceCropMemento(this, cropRectangle), false); + SetImage(tmpImage, false); + } + public bool isCropPossible(ref Rectangle cropRectangle) { cropRectangle = Helpers.GuiRectangle.GetGuiRectangle(cropRectangle.Left, cropRectangle.Top, cropRectangle.Width, cropRectangle.Height); if (cropRectangle.Left < 0) cropRectangle = new Rectangle(0, cropRectangle.Top, cropRectangle.Width + cropRectangle.Left, cropRectangle.Height); @@ -738,7 +751,7 @@ namespace Greenshot.Drawing { selectedElements.OnDoubleClick(); selectedElements.Invalidate(); } - + private Image GetImage(RenderMode renderMode) { // Generate a copy of the original image with a dpi equal to the default... Bitmap clone = ImageHelper.CloneImageToBitmap(Image); diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 88b72d876..c8234ed01 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -297,5 +297,92 @@ namespace GreenshotPlugin.Core { } return returnIcon; } + + /// + /// Make the picture look like it's torn + /// + /// Bitmap to modify + public static void ApplyTornEdge(Bitmap bitmap) { + GraphicsPath path = new GraphicsPath(); + Random random = new Random(); + int regionWidth = 14; + int regionHeight = 14; + int HorizontalRegions = (int)(bitmap.Width / regionWidth); + int VerticalRegions = (int)(bitmap.Height / regionHeight); + int distance = 12; + + // Start + Point previousEndingPoint = Point.Empty; + Point newEndingPoint = Point.Empty; + + // Top + for (int i = 0; i < HorizontalRegions; i++) { + int x = (int)previousEndingPoint.X + regionWidth; + int y = random.Next(0, distance); + newEndingPoint = new Point(x, y); + path.AddLine(previousEndingPoint, newEndingPoint); + previousEndingPoint = newEndingPoint; + } + // end top + newEndingPoint = new Point(bitmap.Width, 0); + path.AddLine(previousEndingPoint, newEndingPoint); + previousEndingPoint = newEndingPoint; + path.CloseFigure(); + + // Right + for (int i = 0; i < VerticalRegions; i++) { + int x = bitmap.Width - random.Next(0, distance); + int y = (int)previousEndingPoint.Y + regionHeight; + newEndingPoint = new Point(x, y); + path.AddLine(previousEndingPoint, newEndingPoint); + previousEndingPoint = newEndingPoint; + } + // end right + newEndingPoint = new Point(bitmap.Width, bitmap.Height); + path.AddLine(previousEndingPoint, newEndingPoint); + previousEndingPoint = newEndingPoint; + path.CloseFigure(); + + // Bottom + for (int i = 0; i < HorizontalRegions; i++) { + int x = (int)previousEndingPoint.X - regionWidth; + int y = bitmap.Height - random.Next(0, distance); + newEndingPoint = new Point(x, y); + path.AddLine(previousEndingPoint, newEndingPoint); + previousEndingPoint = newEndingPoint; + } + // end Bottom + newEndingPoint = new Point(0, bitmap.Height); + path.AddLine(previousEndingPoint, newEndingPoint); + previousEndingPoint = newEndingPoint; + path.CloseFigure(); + + // Left + for (int i = 0; i < VerticalRegions; i++) { + int x = random.Next(0, distance); + int y = (int)previousEndingPoint.Y - regionHeight; + newEndingPoint = new Point(x, y); + path.AddLine(previousEndingPoint, newEndingPoint); + previousEndingPoint = newEndingPoint; + } + // end Left + newEndingPoint = new Point(0, 0); + path.AddLine(previousEndingPoint, newEndingPoint); + previousEndingPoint = newEndingPoint; + path.CloseFigure(); + + // Draw + using (Graphics graphics = Graphics.FromImage(bitmap)) { + Color fillColor = Color.White; + if (bitmap.PixelFormat == PixelFormat.Format32bppArgb) { + graphics.SetClip(path); + graphics.Clear(Color.Transparent); + } else { + using (Brush brush = new SolidBrush( Color.White)) { + graphics.FillPath(brush, path); + } + } + } + } } }