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
This commit is contained in:
RKrom 2012-02-08 13:12:55 +00:00
parent 89c7c26c5a
commit dbc77613f2

View file

@ -305,8 +305,7 @@ namespace GreenshotPlugin.Core {
/// <param name="sourceBitmap">Bitmap to make torn edge off</param> /// <param name="sourceBitmap">Bitmap to make torn edge off</param>
/// <returns>Changed bitmap</returns> /// <returns>Changed bitmap</returns>
public static Bitmap CreateTornEdge(Bitmap sourceBitmap) { public static Bitmap CreateTornEdge(Bitmap sourceBitmap) {
Rectangle cropRectangle = new Rectangle(Point.Empty, sourceBitmap.Size); Bitmap returnImage = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format32bppArgb);
Bitmap returnImage = sourceBitmap.Clone(cropRectangle, PixelFormat.Format32bppArgb);
try { try {
returnImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution); returnImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
} catch (Exception ex) { } catch (Exception ex) {
@ -321,9 +320,8 @@ namespace GreenshotPlugin.Core {
int distance = 12; int distance = 12;
// Start // Start
Point previousEndingPoint = Point.Empty; Point previousEndingPoint = new Point(regionWidth, random.Next(1, distance));
Point newEndingPoint = Point.Empty; Point newEndingPoint;
path.AddLine(new Point(sourceBitmap.Width, 0), Point.Empty);
// Top // Top
for (int i = 0; i < HorizontalRegions; i++) { for (int i = 0; i < HorizontalRegions; i++) {
int x = (int)previousEndingPoint.X + regionWidth; int x = (int)previousEndingPoint.X + regionWidth;
@ -332,11 +330,6 @@ namespace GreenshotPlugin.Core {
path.AddLine(previousEndingPoint, newEndingPoint); path.AddLine(previousEndingPoint, newEndingPoint);
previousEndingPoint = newEndingPoint; previousEndingPoint = newEndingPoint;
} }
// end top
newEndingPoint = new Point(sourceBitmap.Width, 0);
path.AddLine(previousEndingPoint, newEndingPoint);
previousEndingPoint = newEndingPoint;
path.CloseFigure();
// Right // Right
for (int i = 0; i < VerticalRegions; i++) { for (int i = 0; i < VerticalRegions; i++) {
@ -346,11 +339,6 @@ namespace GreenshotPlugin.Core {
path.AddLine(previousEndingPoint, newEndingPoint); path.AddLine(previousEndingPoint, newEndingPoint);
previousEndingPoint = newEndingPoint; previousEndingPoint = newEndingPoint;
} }
// end right
newEndingPoint = new Point(sourceBitmap.Width, sourceBitmap.Height);
path.AddLine(previousEndingPoint, newEndingPoint);
previousEndingPoint = newEndingPoint;
path.CloseFigure();
// Bottom // Bottom
for (int i = 0; i < HorizontalRegions; i++) { for (int i = 0; i < HorizontalRegions; i++) {
@ -360,11 +348,6 @@ namespace GreenshotPlugin.Core {
path.AddLine(previousEndingPoint, newEndingPoint); path.AddLine(previousEndingPoint, newEndingPoint);
previousEndingPoint = newEndingPoint; previousEndingPoint = newEndingPoint;
} }
// end Bottom
newEndingPoint = new Point(0, sourceBitmap.Height);
path.AddLine(previousEndingPoint, newEndingPoint);
previousEndingPoint = newEndingPoint;
path.CloseFigure();
// Left // Left
for (int i = 0; i < VerticalRegions; i++) { for (int i = 0; i < VerticalRegions; i++) {
@ -374,10 +357,6 @@ namespace GreenshotPlugin.Core {
path.AddLine(previousEndingPoint, newEndingPoint); path.AddLine(previousEndingPoint, newEndingPoint);
previousEndingPoint = newEndingPoint; previousEndingPoint = newEndingPoint;
} }
// end Left
newEndingPoint = new Point(0, 0);
path.AddLine(previousEndingPoint, newEndingPoint);
previousEndingPoint = newEndingPoint;
path.CloseFigure(); path.CloseFigure();
// Draw // Draw
@ -386,15 +365,8 @@ namespace GreenshotPlugin.Core {
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
using (Brush brush = new TextureBrush(sourceBitmap)) {
if (Image.IsAlphaPixelFormat(returnImage.PixelFormat)) { graphics.FillPath(brush, path);
// 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);
}
} }
} }
return returnImage; return returnImage;