This article mainly introduces the C # automatic generation of beautiful crystal effect avatar implementation code, a friend in need can refer to the
As with other micro-blogging systems, users in the "multi-Intranet microblogging system" can also upload their avatar and support avatar clipping. But "multi-intranet micro-blogging system" can be more beautiful head, because the system to achieve the crystal effect of the head. C # program to achieve the crystal effect of the image of the process is: (1) thumbnail to the width or height of =90 head, (2) by the user to select the appropriate location to cut 90x90 final head; (3) Add crystal Effect; Code dedication: The code is as follows:///<summary>///to draw the crystal effect of Avatar///</summary>///<param name= "Containspage" ></param>///< Param name= "W" ></param>///<param name= "h" ></param>///<param name= "memostring" ></ param> public static void Avatar (Page containspage, string filename, int r, int m, int s, int x, int y, bool save, Stri ng New_avatar) {System.Drawing.Image imagesrc = System.Drawing.Image.FromFile (HttpContext.Current.Server.MapPath ("/ ") + filename); int w = imagesrc.width; int h = imagesrc.height; if (r = = 1 | | r = = 3) {h = imagesrc.width w = imagesrc.height} if (save) {w = h = \ n] if (w &G T ) W = 300; if (h >) h = 300; Color BackColor = color.darkturquoise; Size size = new Size (w, h); System.drawIng. Bitmap btnbmp = new Bitmap (w, h); Graphics g = graphics.fromimage (btnbmp); //Reset background color, you can customize G.clear (Color.White); Color clr = BackColor; G.smoothingmode = smoothingmode.antialias;//anti-aliasing g.compositingquality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; G.interpolationmode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; //Create button graphics-Brush int btnoff = 0;//button margin Rectangle RC1 = new Rectangle (Btnoff, Btnoff, size. Width-1-Btnoff, size. Height-1-Btnoff); GraphicsPath gpath1 = Getgraphicspath (RC1, 10); GraphicsPath gpath1a = Getgraphicspath (RC1, 15); LinearGradientBrush BR1 = new LinearGradientBrush (0, 0), new Point (0, RC1. Height + 6), CLR, Color.White; //Create button shadow-brush int shadowoff = 1;//Shadow margin Rectangle rc2 = RC1; RC2. Offset (0, Shadowoff); GraphicsPath gpath2 = Getgraphicspath (RC2, 10); PathGradientBrush Br2 = new PathGradientBrush (gpath2); Br2. Centercolor = Color.FromArgb (0, 0, 0); Color.Black; Br2. Surroundcolors= new color[] {Color.FromArgb (+,), Color.FromArgb (64, 128, 128, 128)}; Systemcolors.buttonface //To be more realistic, we set the gradient end color to the form foreground color, which adjusts//creates the top white gradient of the button-brush Rectangle RC3 = RC1; Rc3. Inflate (-1,-1); Rc3. Height = 15; GraphicsPath gpath3 = Getgraphicspath (RC3, 10); LinearGradientBrush Br3 = new LinearGradientBrush (RC3, Color.FromArgb (255, Color.White), Color.FromArgb (0, Color.White ), lineargradientmode.vertical); //Draw graphics//Draw shadows if (S > 0) {g.fillpath (Br2, gpath2);} //Draw button if (S > 0) {g.fillpath (BR1, gpath1);} & nbsp if (S > 0)//{g.setclip (gpath1a, combinemode.replace);//} switch (m) {Case 1: _currentbitmap = (Bitmap) imag ESRC; RotateFlip (ROTATEFLIPTYPE.ROTATENONEFLIPX); IMAGESRC = (System.Drawing.Image) _currentbitmap; Break Case 2: _currentbitmap = (Bitmap) imagesrc; RotateFlip (rotatefliptype.rotatenoneflipy); IMAGESRC = (System.Drawing.Image) _currentbitmap; Break Default:break; } Switch (r) {Case 1: _currentbitmap = (Bitmap) imagesrc; RotateFlip (Rotatefliptype.rotate90flipnone); IMAGESRC = (System.Drawing.Image) _currentbitmap; Break Case 2: _currentbitmap = (Bitmap) imagesrc; RotateFlip (Rotatefliptype.rotate180flipnone); IMAGESRC = (System.Drawing.Image) _currentbitmap; Break Case 3: _currentbitmap = (Bitmap) imagesrc; RotateFlip (Rotatefliptype.rotate270flipnone); IMAGESRC = (System.Drawing.Image) _currentbitmap; Break Default:break; } G.drawimage (IMAGESRC,-X,-y); //Draw top White bubbles if (S > 0) {g.fillpath (Br3, gpath3);} Imagesrc.dispose (); G.dispose (); MemoryStream stream = new MemoryStream (); Btnbmp. Save (stream, System.Drawing.Imaging.ImageFormat.Png); if (save) {try {//Save this original picture in the specified format with the specified codec parameter to the specified file string sfile = HttpContext.Current.Server.MapPath ("/") + NE W_avatar; Btnbmp. Save (sfile); catch (System.Exception e) {throw e;}} //Output picture containspage containsPage.Response.Expires = 0; ContainsPage.Response.ExpiresAbsolute = System.DateTime.Now.AdDseconds (-1); ContainsPage.Response.AddHeader ("Pragma", "no-cache"); ContainsPage.Response.AddHeader ("Cache-control", "private"); ContainsPage.Response.CacheControl = "No-cache"; ContainsPage.Response.Clear (); ContainsPage.Response.ContentType = "Image/png"; ContainsPage.Response.BinaryWrite (stream. ToArray ()); }