Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Graphics - Drawing in ASP.NET 2.0 and VB.NET
Drawing in ASP.NET 2.0 and VB.NET


ASP.NET Graphics Tutorial

This tutorial will show you how to draw pie and font in ASP.NET and VB.NET 2.0 by using the classes of Graphics.

Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!


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;
using System.Drawing.Imaging;
using System.Drawing.Text;

Create canvas and fill the background

Dim objBitmap As New System.Drawing.Bitmap(400, 440)
Dim objGraphics As System.Drawing.Graphics
objGraphics = System.Drawing.Graphics.FromImage(objBitmap)
objGraphics.Clear(Drawing.Color.White)

Draw the pie and fill

Dim p As New Drawing.Pen(Drawing.Color.Yellow, 0)
Dim rect As New Drawing.Rectangle(10, 10, 280, 280)
objGraphics.DrawEllipse(p, rect)

Dim b1 As New Drawing.SolidBrush(Drawing.Color.Red)
Dim b2 As New Drawing.SolidBrush(Drawing.Color.Green)
Dim b3 As New Drawing.SolidBrush(Drawing.Color.Blue)
objGraphics.FillPie(b1, rect, 0.0F, 90.0F)
objGraphics.FillPie(b2, rect, 90.0F, 60.0F)
objGraphics.FillPie(b3, rect, 150.0F, 210.0F)


Draw font

Dim fontfml As New Drawing.FontFamily(Drawing.Text.GenericFontFamilies.Serif)
Dim font As New Drawing.Font(fontfml, 14)
Dim brush As New Drawing.SolidBrush(Drawing.Color.Blue)
objGraphics.DrawString("Draw Graphics", font, brush, 100, 300)

Export and save to picture

objBitmap.Save(Response.OutputStream, Drawing.Imaging.ImageFormat.Gif)
objBitmap.Save(Server.MapPath("x.jpg"), Drawing.Imaging.ImageFormat.Jpeg)

End drawing

objBitmap.Dispose()
objGraphics.Dispose()


Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

 







 
  Developer Resources







Server Intellect Rocks