C # Drawing--graphics

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.