C # To achieve a simple drawing function can take advantage of the graphics class, to use the graphics required by the using namespace System.Drawing (this namespace is all about graphics operations). First create the canvas:
New Bitmap (+ = graphics.fromimage (BMP);
Clears the background color of the canvas and specifies a color fill:
G.clear (Color.White);
Start Drawing:
//Draw a rectangleG.drawrectangle (NewPen (color.red),NewRectangle (0,0, -, -));//Fill SectorG.fillpie (NewSolidBrush (color.red),NewRectangle ( -, the, $, $),0, -);//write text on the canvasg.DrawString ("A",NewFont ("Times New Roman", -),NewSolidBrush (Color.Black), -, About);
The complete code is given below:
1 Public classGraphicscontroller:controller2 {3 Publicactionresult Index ()4 {5 returnView ();6 }7 [HttpGet]8 Publicactionresult creategraphics ()9 {TenBitmap BMP =NewBitmap ( +, -); One //Canvas AGraphics g =graphics.fromimage (BMP); - //clears the canvas background color and fills the specified color - g.clear (color.white); the //Draw a rectangle -G.drawrectangle (NewPen (color.red),NewRectangle (0,0, -, -)); - //painting Brushes -Brush bs =NewSolidBrush (color.blue); + //Fill Sector -G.fillpie (NewSolidBrush (color.red),NewRectangle ( -, the, $, $),0, -); +G.fillpie (BS,NewRectangle ( -, the, $, $), -, -); AG.drawpie (NewPen (BS),NewRectangle ( -, the, $, $), $, -);//Draw Fan atG.fillpie (NewSolidBrush (Color.hotpink),NewRectangle ( -, the, $, $), -, -); -g.DrawString ("A",NewFont ("Times New Roman", -),NewSolidBrush (Color.Black), -, About); - //anti-aliasing -G.smoothingmode =Smoothingmode.antialias; -MemoryStream ms =NewMemoryStream (); - Try in { - bmp. Save (MS, imageformat.gif); to returnFile (Ms. ToArray (),@"Image/gif"); + } - Catch(Exception) the { * return NULL; $ }Panax Notoginseng } -}
Backstage
@{
Layout = null;
}
<! DOCTYPE html>
<meta name= "viewport" content= "Width=device-width"/>
<title>Index</title>
<body>
<div>
</div>
</body>
(It seems a bit shabby (╯▽╰)):
Finally recommend some of the predecessors of the summary (more than I was too strong):
Http://www.cnblogs.com/Jerry-Chou/archive/2012/03/20/2408064.html
Http://www.cnblogs.com/Jerry-Chou/archive/2012/03/21/2409590.html
Http://www.cnblogs.com/beyond0309/archive/2008/04/15/1155003.html Verification code can also be generated in this way
C # Drawing--graphics