Public class MyGDI
{
Public static void CreateWatermark (string sSrcFilePath, string sDstFilePath, string sText1, string sColor1, string sSize1, string sFont1, string sText2, string sColor2, string sSize2, string sFont2, string sBgColor, string sTransparence)
{
System. Drawing. Image image = System. Drawing. Image. FromFile (sSrcFilePath );
Graphics g = Graphics. FromImage (image );
G. SmoothingMode = SmoothingMode. AntiAlias;
G. InterpolationMode = InterpolationMode. HighQualityBicubic;
G. CompositingQuality = CompositingQuality. HighQuality;
G. TextRenderingHint = System. Drawing. Text. TextRenderingHint. AntiAlias; // anti-aliasing of Text
G. DrawImage (image, 0, 0, image. Width, image. Height );
Font f1 = new Font (sFont1, float. Parse (sSize1 ));
Font f2 = new Font (sFont2, float. Parse (sSize2 ));
Brush brushfortext1 = new SolidBrush (ColorTranslator. FromHtml (sColor1 ));
Brush brushfortext2 = new SolidBrush (ColorTranslator. FromHtml (sColor2 ));
Brush brushforbg = new SolidBrush (Color. FromArgb (Convert. ToInt16 (255 * float. Parse (sTransparence), ColorTranslator. FromHtml (sBgColor )));
G. RotateTransform (-20 );
Rectangle rect = new Rectangle (-image. Width/2-50, image. Height-50, image. Width * 2, 40 );
G. DrawRectangle (new Pen (brushforbg), rect );
G. FillRectangle (brushforbg, rect );
Rectangle rectfortext1 = new Rectangle (-image. Width/2 + image. Width/5, image. Height-45, image. Width * 2, 60 );
For (int I = 0; I <10; I ++)
G. DrawString (sText1, f1, brushfortext1, rectfortext1 );
Rectangle rectfortext2 = new Rectangle (-image. Width/2 + image. Width/5, image. Height-25, image. Width * 2, 60 );
For (int I = 0; I <10; I ++)
G. DrawString (sText2, f2, brushfortext2, rectfortext2 );
Image. Save (sDstFilePath, ImageFormat. Jpeg );
Image. Dispose ();
}
Public static void CreateRoundedCorner (string sSrcFilePath, string sDstFilePath, string sCornerLocation)
{
System. Drawing. Image image = System. Drawing. Image. FromFile (sSrcFilePath );
Graphics g = Graphics. FromImage (image );
G. SmoothingMode = SmoothingMode. HighQuality;
G. InterpolationMode = InterpolationMode. HighQualityBicubic;
G. CompositingQuality = CompositingQuality. HighQuality;
Rectangle rect = new Rectangle (0, 0, image. Width, image. Height );
GraphicsPath rectPath = CreateRoundRectanglePath (rect, image. Width/10, sCornerLocation); // construct the external path of the rounded corner
Brush B = new SolidBrush (Color. White); // rounded corner Background White
G. DrawPath (new Pen (B), rectPath );
G. FillPath (B, rectPath );
G. Dispose ();
Image. Save (sDstFilePath, ImageFormat. Jpeg );
Image. Dispose ();
}
Public static void CreatePlainText (string sSrcFilePath, string sDstFilePath, string sText, string sColor, string sSize, string sFont)
{
System. Drawing. Image image = System. Drawing. Image. FromFile (sSrcFilePath );
Graphics g = Graphics. FromImage (image );
G. SmoothingMode = SmoothingMode. AntiAlias;
G. InterpolationMode = InterpolationMode. HighQualityBicubic;
G. CompositingQuality = CompositingQuality. HighQuality;
G. DrawImage (image, 0, 0, image. Width, image. Height );
G. TextRenderingHint = System. Drawing. Text. TextRenderingHint. AntiAlias; // anti-aliasing of Text
Font f = new Font (sFont, float. Parse (sSize ));
Brush B = new SolidBrush (ColorTranslator. FromHtml (sColor ));
Rectangle rect = new Rectangle (10, 5, image. Width, image. Height); // open a distance appropriately
For (int I = 0; I <30; I ++) // enhance the brightness
G. DrawString (sText, f, B, rect );
Image. Save (sDstFilePath, ImageFormat. Jpeg );
Image. Dispose ();
}
Private static GraphicsPath CreateRoundRectanglePath (Rectangle rect, int radius, string sPosition)
{
GraphicsPath rectPath = new GraphicsPath ();
Switch (sPosition)
{
Case "TopLeft ":
{
RectPath. AddArc (rect. Left, rect. Top, radius * 2, radius * 2,180, 90 );
RectPath. AddLine (rect. Left, rect. Top, rect. Left, rect. Top + radius );
Break;
}
Case "TopRight ":
{
RectPath. AddArc (rect. Right-radius * 2, rect. Top, radius * 2, radius * 2,270, 90 );
RectPath. AddLine (rect. Right, rect. Top, rect. Right-radius, rect. Top );
Break;
}
Case "BottomLeft ":
{
RectPath. AddArc (rect. Left, rect. Bottom-radius * 2, radius * 2, radius * 2, 90, 90 );
RectPath. AddLine (rect. Left, rect. Bottom-radius, rect. Left, rect. Bottom );
Break;
}
Case "BottomRight ":
{
RectPath. AddArc (rect. Right-radius * 2, rect. Bottom-radius * 2, radius * 2, radius * 2, 0, 90 );
RectPath. AddLine (rect. Right-radius, rect. Bottom, rect. Right, rect. Bottom );
Break;
}
}
Return rectPath;
}
}