asp.net some common applications of GDI + (watermark, text, fillet processing) Skills _ practical skills
Last Update:2017-01-18
Source: Internet
Author: User
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; Text anti-aliasing
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 < 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 < 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); Building rounded external paths
Brush B = new SolidBrush (color.white);//Fillet 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, str ing 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; Text anti-aliasing
Font f = new Font (sfont,float. Parse (ssize));
Brush B = New SolidBrush (colortranslator.fromhtml (Scolor));
Rectangle rect = new Rectangle (5, image. Width, image. Height); To open a distance with proper space
for (int i = 0; i < i++)//Enhance 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;
}
}