

Navigator : Home > Tutorials > Graphics Tutorials > ...
Drawing in ASP.NET 2.0 and C#
This tutorial will show you how to draw pie and font in ASP.NET 2.0 and C# by using the classes of Graphics.
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
We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!
and System.Drawing.Text , .Net provides more advanced functionalities.
using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Text; |
Create canvas and fill the background
Bitmap objBitmap; Graphics objGraphics;
objBitmap = new Bitmap(400, 440); objGraphics = Graphics.FromImage(objBitmap);
objGraphics.Clear(Color.White); |
Draw the pie and fill
Pen p=new Pen(Color.Yellow,0); 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); |
Draw font
FontFamily fontfml = new FontFamily(GenericFontFamilies.Serif); Font font = new Font(fontfml, 16); SolidBrush brush = new SolidBrush(Color.Blue); objGraphics.DrawString("Drawing Graphics", font, brush, 70, 300); |
Export and save to picture
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
objBitmap.Save(Response.OutputStream, ImageFormat.Gif); objBitmap.Save(Server.MapPath("x.jpg"), ImageFormat.Jpeg);
|
End drawing
objBitmap.Dispose(); objGraphics.Dispose();
|
Looking for the VB.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.