1: /*
2: Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>
3:
4: Permission is hereby granted, free of charge, to any person obtaining a copy
5: of this software and associated documentation files (the "Software"), to deal
6: in the Software without restriction, including without limitation the rights
7: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8: copies of the Software, and to permit persons to whom the Software is
9: furnished to do so, subject to the following conditions:
10:
11: The above copyright notice and this permission notice shall be included in
12: all copies or substantial portions of the Software.
13:
14: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20: THE SOFTWARE.*/
21:
22: #region Usings
23: using System.Drawing;
24: using System.Drawing.Drawing2D;
25: #endregion
26:
27: namespace Utilities.Media.Image
28: {
29: /// <summary>
30: /// Class for drawing various shapes
31: /// </summary>
32: public static class Draw
33: {
34: #region Public Static Functions
35:
36: /// <summary>
37: /// Draws a rounded rectangle on a bitmap
38: /// </summary>
39: /// <param name="Image">Image to draw on</param>
40: /// <param name="BoxColor">The color that the box should be</param>
41: /// <param name="XPosition">The upper right corner's x position</param>
42: /// <param name="YPosition">The upper right corner's y position</param>
43: /// <param name="Height">Height of the box</param>
44: /// <param name="Width">Width of the box</param>
45: /// <param name="CornerRadius">Radius of the corners</param>
46: /// <returns>The bitmap with the rounded box on it</returns>
47: public static Bitmap DrawRoundedRectangle(Bitmap Image, Color BoxColor, int XPosition, int YPosition,
48: int Height, int Width, int CornerRadius)
49: {
50: Bitmap NewBitmap = new Bitmap(Image, Image.Width, Image.Height);
51: using (Graphics NewGraphics = Graphics.FromImage(NewBitmap))
52: {
53: using (Pen BoxPen = new Pen(BoxColor))
54: {
55: using (GraphicsPath Path = new GraphicsPath())
56: {
57: Path.AddLine(XPosition + CornerRadius, YPosition, XPosition + Width - (CornerRadius * 2), YPosition);
58: Path.AddArc(XPosition + Width - (CornerRadius * 2), YPosition, CornerRadius * 2, CornerRadius * 2, 270, 90);
59: Path.AddLine(XPosition + Width, YPosition + CornerRadius, XPosition + Width, YPosition + Height - (CornerRadius * 2));
60: Path.AddArc(XPosition + Width - (CornerRadius * 2), YPosition + Height - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 0, 90);
61: Path.AddLine(XPosition + Width - (CornerRadius * 2), YPosition + Height, XPosition + CornerRadius, YPosition + Height);
62: Path.AddArc(XPosition, YPosition + Height - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 90, 90);
63: Path.AddLine(XPosition, YPosition + Height - (CornerRadius * 2), XPosition, YPosition + CornerRadius);
64: Path.AddArc(XPosition, YPosition, CornerRadius * 2, CornerRadius * 2, 180, 90);
65: Path.CloseFigure();
66: NewGraphics.DrawPath(BoxPen, Path);
67: }
68: }
69: }
70: return NewBitmap;
71: }
72:
73: #endregion
74: }
75: }