Introduction
Based on the generation of images to achieve a mobile phone number of the need to turn pictures. Content is also very simple, directly using mobile phone number to generate a PNG image. is for the background to be transparent so that other places are invoked. There is no sawtooth mainly relies on a code: G. Textrenderinghint= Textrenderinghint.antialias;
Generate pictures
1, serrated
2, no Sawtooth
Generation method
String color = "#ff6633";
System.Drawing.Bitmap image = new System.Drawing.Bitmap (170, 35);
Graphics g = graphics.fromimage (image); try {g.textrenderinghint= Textrenderinghint.antialias;//anti-aliasing//Generate random generator Random Random = new
Random ();
Clear the picture background color//g.clear (color.transparent); Picture background noise line/*for (int i = 0; i < 2; i++) {int x1 = random. Next (image.
Width); int x2 = random. Next (image.
Width); int y1 = random. Next (image.
Height); int y2 = random. Next (image.
Height);
G.drawline (New Pen (Color.Black), x1, y1, x2, y2);
} * * System.Drawing.ColorConverter Colconvert = new System.Drawing.ColorConverter ();
Color FontColor = (System.Drawing.Color) colconvert.convertfromstring (color);
Font font = new System.Drawing.Font ("Arial", System.Drawing.FontStyle.Bold); LinearGradientBrush brush = new LinearGradientBrush (new Rectangle (0, 0, image. Width, ImagE.height), FontColor, fontcolor,lineargradientmode.horizontal);
g.DrawString (phone, font, brush, 2, 2); Picture the foreground noise point//for (int i = 0; i < i++)//{//int x = random. Next (image.
Width); int y = random. Next (image.
Height); Image. SetPixel (x, Y, Color.FromArgb) (random.
Next ())); ///Draw the picture's border line//g.drawrectangle (new Pen (Color.White), 0, 0, image. Width-1, image.
HEIGHT-1);
System.IO.MemoryStream ms = new System.IO.MemoryStream (); Color BackColor = image.
GetPixel (1, 1); Image.
Maketransparent (BackColor); Image.
Save (MS, System.Drawing.Imaging.ImageFormat.Png); Context.
Response.clearcontent (); Context.
Response.ContentType = "Image/x-png"; Context. Response.BinaryWrite (Ms.
ToArray ());
finally {g.dispose (); Image.
Dispose ();
}
Resources
Http://www.blue1000.com/bkhtml/c17/2013-03/71115.htm
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.