From dbc77613f2dd1fdf6b3c6eed1c3664efbbf317f6 Mon Sep 17 00:00:00 2001 From: RKrom Date: Wed, 8 Feb 2012 13:12:55 +0000 Subject: [PATCH] Simplified edge code and improved the quality too! git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1641 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/ImageHelper.cs | 38 ++++------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index fce665abe..dcfa72b51 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -305,8 +305,7 @@ namespace GreenshotPlugin.Core { /// Bitmap to make torn edge off /// Changed bitmap public static Bitmap CreateTornEdge(Bitmap sourceBitmap) { - Rectangle cropRectangle = new Rectangle(Point.Empty, sourceBitmap.Size); - Bitmap returnImage = sourceBitmap.Clone(cropRectangle, PixelFormat.Format32bppArgb); + Bitmap returnImage = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format32bppArgb); try { returnImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution); } catch (Exception ex) { @@ -321,9 +320,8 @@ namespace GreenshotPlugin.Core { int distance = 12; // Start - Point previousEndingPoint = Point.Empty; - Point newEndingPoint = Point.Empty; - path.AddLine(new Point(sourceBitmap.Width, 0), Point.Empty); + Point previousEndingPoint = new Point(regionWidth, random.Next(1, distance)); + Point newEndingPoint; // Top for (int i = 0; i < HorizontalRegions; i++) { int x = (int)previousEndingPoint.X + regionWidth; @@ -332,11 +330,6 @@ namespace GreenshotPlugin.Core { path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } - // end top - newEndingPoint = new Point(sourceBitmap.Width, 0); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; - path.CloseFigure(); // Right for (int i = 0; i < VerticalRegions; i++) { @@ -346,11 +339,6 @@ namespace GreenshotPlugin.Core { path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } - // end right - newEndingPoint = new Point(sourceBitmap.Width, sourceBitmap.Height); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; - path.CloseFigure(); // Bottom for (int i = 0; i < HorizontalRegions; i++) { @@ -360,11 +348,6 @@ namespace GreenshotPlugin.Core { path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } - // end Bottom - newEndingPoint = new Point(0, sourceBitmap.Height); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; - path.CloseFigure(); // Left for (int i = 0; i < VerticalRegions; i++) { @@ -374,10 +357,6 @@ namespace GreenshotPlugin.Core { path.AddLine(previousEndingPoint, newEndingPoint); previousEndingPoint = newEndingPoint; } - // end Left - newEndingPoint = new Point(0, 0); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; path.CloseFigure(); // Draw @@ -386,15 +365,8 @@ namespace GreenshotPlugin.Core { graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; - - if (Image.IsAlphaPixelFormat(returnImage.PixelFormat)) { - // When using transparency we can't draw with Color.Transparency so we clear - graphics.SetClip(path); - graphics.Clear(Color.Transparent); - } else { - using (Brush brush = new SolidBrush(Color.White)) { - graphics.FillPath(brush, path); - } + using (Brush brush = new TextureBrush(sourceBitmap)) { + graphics.FillPath(brush, path); } } return returnImage;