The class of Graphics provide the method of drawing to display device. For instance, the Rectangle, point and others GDI+ basic components that can be assembled. The class of Pen is used for drawing line and curve, while the classes derived from the abstract class Brush can be used for fill the shape. The class of FontFamily have the similar design, but have a little bit of differences on modality.
First, you will need to import the System.Drawing, System.Drawing.Imaging, System.Drawing.Text namespace.
The namespace of system.Drawing provides the access to basic GDI+ graphic function. In the namespace of System.Drawing.Drawing2D, System.Drawing.Imaging and System.Drawing.Text , .Net provides more advanced functionalities.
using System.Drawing;Create canvas and fill the background
using System.Drawing.Imaging;
using System.Drawing.Text;
Bitmap objBitmap;
Graphics objGraphics;
objBitmap = new Bitmap(400, 440);Draw the pie and fill
objGraphics = Graphics.FromImage(objBitmap);
objGraphics.Clear(Color.White);
Pen p=new Pen(Color.Yellow,0);Draw font
Rectangle rect=new Rectangle(10,10,280,280);
objGraphics.DrawEllipse(p,rect);
Brush b1=new SolidBrush(Color.Red);
Brush b2=new SolidBrush(Color.Green);
Brush b3=new SolidBrush(Color.Blue);
objGraphics.FillPie(b1, rect, 0f, 60f);
objGraphics.FillPie(b2, rect, 60f, 150f);
objGraphics.FillPie(b3, rect, 210f, 150f);
FontFamily fontfml = new FontFamily(GenericFontFamilies.Serif);Export and save to picture
Font font = new Font(fontfml, 16);
SolidBrush brush = new SolidBrush(Color.Blue);
objGraphics.DrawString("Drawing Graphics", font, brush, 70, 300);
objBitmap.Save(Response.OutputStream, ImageFormat.Gif);End drawing
objBitmap.Save(Server.MapPath("x.jpg"), ImageFormat.Jpeg);
objBitmap.Dispose();
objGraphics.Dispose();
No comments:
Post a Comment