Added an edge effect to see how and where we place them.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1638 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-02-07 16:28:28 +00:00
parent 034daa3957
commit a52e83dc45
2 changed files with 102 additions and 2 deletions

View file

@ -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);

View file

@ -297,5 +297,92 @@ namespace GreenshotPlugin.Core {
}
return returnIcon;
}
/// <summary>
/// Make the picture look like it's torn
/// </summary>
/// <param name="bitmap">Bitmap to modify</param>
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);
}
}
}
}
}
}