DotNet Tutorials

Server Intellect

 Drawing in ASP.NET 2.0 and VB.NET

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. 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 migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!

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

If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!

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

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!

objBitmap.Dispose()
objGraphics.Dispose()




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

Looking for more ASP.NET Tutorials? Click Here!

 

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect