A Bunch of useful GDI+ methods and extensions that can be used for many purposes.
.NET Framework 3.5 or higher
-
Rectangles
-
Colors
-
Drawings
-
Images
-
Strings
using GDIHelper;
private readonly Methods _instance = new Methods();
Font fontfile = _instance.GetFont("fontbytearray /* e.g : a font stored in resources */, fontsize, fontstyle);
using GDIHelper;
private readonly Methods _instance = new Methods();
Font fontfile = _instance.GetFont("Font path" /* e.g : C:fontfile.ttf */, fontsize, fontstyle);
using GDIHelper;
private readonly Methods _instance = new Methods();
StringFormat stringFormat = _instance.SetAlignment(StringAlignment.Center, StringAlignment.Near);
using GDIHelper;
private readonly Methods _instance = new Methods();
GraphicsPath GP = new GraphicsPath();
GP.AddRectangle(new Rectangle(10, 10, 23, 45));
Brush solidBrush = _instance.GlowBrush(Color.Brown, new Color[] {Color.Black, Color.DarkRed}, new PointF(5, 8), GP, WrapMode.Clamp);
using GDIHelper;
private readonly Methods _instance = new Methods();
GraphicsPath GP = new GraphicsPath();
GP.AddRectangle(new Rectangle(10, 10, 23, 45));
Brush solidBrush = _instance.GlowBrush(Color.Brown, new Color[] {Color.Black, Color.DarkRed}, new PointF[]{new PointF(12,10), new PointF(0, 2) }, WrapMode.Tile);
GraphicsPath GP = new Rectangle(0, 0, 10, 10).RoundRec(12, true, true, true, true);
string htmlColor = Color.Brown.ToHTML();
SolidBrush solidBrush = Color.MediumBlue.ToBrush();
Pen pen = Color.Brown.ToPen();
string rgb = Color.Aquamarine.ToRGBString();
Output :
rgb(127, 255, 212)
string rgba = Color.Aquamarine.ToRGBAString();
Output :
rgba(127, 255, 212, 255)
string argb = Color.Aquamarine.ToARGBString();
Output :
argb(255, 127, 255, 212)
Color color = new Color[]{Color.Black, Color.Blue}.MixColors();
Graphics g = CreateGraphics();
/// DrawImageFromBase64(string base64Image, Rectangle rect)
g.DrawImageFromBase64("base64 image", new Rectangle(0, 0, 12, 12));
Graphics g = CreateGraphics();
/// DrawColoredImage(Rectangle r, string base64Image, Color c)
g.DrawColoredImage(new Rectangle(0, 0, 12, 12), "base64 image", Color.Black);
Graphics g = CreateGraphics();
Image image = Image.FromFile("image path");
// DrawColoredImage(Rectangle r, Image image, Color c)
g.DrawColoredImage(new Rectangle(0, 0, 12, 12), image, Color.Black);
Graphics g = CreateGraphics();
Image image = Image.FromFile("image path");
// DrawTransparentImage(float alpha, Image image, Rectangle rect)
g.DrawTransparentImage(0.1f, image, new Rectangle(0, 0, 12, 12));
Graphics g = CreateGraphics();
// DrawStrokedRectangle(Rectangle rect, Color bodyColor, Color strokeColor, int strokeThickness = 1)
g.DrawStrokedRectangle(new Rectangle(0, 0, 12, 12), Color.Brown, Color.Black, 2);
Graphics g = CreateGraphics();
// DrawStrokedEllipse(Rectangle rect, Color bodyColor, Color strokeColor, int strokeThickness = 1)
g.DrawStrokedEllipse(new Rectangle(0, 0, 12, 12), Color.Brown, Color.Black, 2);
Graphics g = CreateGraphics();
// DrawRoundedRectangleWithStroke(Rectangle rect, Color bodyColor, Color strokeColor, int strokeThickness = 1, int curve = 1, bool topLeft = true, bool topRight = true,
bool bottomLeft = true, bool bottomRight = true)
g.DrawRoundedRectangleWithStroke(new Rectangle(0, 0, 12, 12), Color.Brown, Color.Black, 2, 10, true, true ,true, true);
Image image = Image.FromFile("image path");
TextureBrush pathGradientBrush = image.ToBrush();
Image image = Image.FromFile("image path");
TextureBrush pathGradientBrush = image.ToBrush(new Rectangle(0, 0, 22, 22));
Image image = Image.FromFile("image path");
// ToPen(float width = 1, LineCap startCap = LineCap.Custom, LineCap endCap = LineCap.Custom)
Pen pen = image.ToPen(2, LineCap.Custom, LineCap.Custom);
Image image = Image.FromFile("image path");
string base64image = image.ToBase64();
string base64Image = "imageinbase64string";
Image image = base64Image.ToImage();
string HTML = "#fff";
// ToColor(int alpha = 255)
Color color = HTML.ToColor(80);
string HTML = "#fff";
// ToBrush(int alpha = 255)
SolidBrush solidBrush = HTML.ToBrush(90);
string HTML = "#fff";
// ToPen(int alpha = 255, float size = 1, LineCap startCap = LineCap.Custom, LineCap endCap = LineCap.Custom)
Pen pen = HTML.ToPen(220, 4, LineCap.Custom, LineCap.Custom);
string fontName = "Arial";
// ToFont(float size, FontStyle fontStyle = FontStyle.Regular, GraphicsUnit unit = GraphicsUnit.Pixel)
Font font = fontName.ToFont(8, FontStyle.Regular, GraphicsUnit.Display);