The Graphics Device Interface (GDI) is a library of classes that allows an application developer to draw graphics on the screen and work with images, such as bitmaps and metafiles. Most GDI classes are part of the System.Drawing namespace in the .NET Framework. In Visual Studio 2005, GDI has been replaced by an enhance version, called GDI+.
GDI+ allows you to draw vector graphics. A vector graphic is a line or shape drawn on a coordinate system. The first step in drawing a graphic is to retrieve a reference to your canvas. The Paint event of a form or control includes an argument named e, which stores a Graphics object. You will use this object as your canvas.
Before you can draw a shape, you must create a pen. A pen defines the color and line width that will be used to draw the shape. You can create a pen by declaring a variable and instantiating an object of the Pen class. For example, to create a pen that draws a 4-pixel red line, you would use the following code:
Dim redPen As New Pen(Color.Red, 4)
You can then use that pen to draw lines and shapes that are not filled. For example, the following code draws a vertical line from point 30, 20 to point 30, 40.
e.Graphics.DrawLine(redPen, 30, 20, 30, 40)
To draw a rectangle outlined in red, you would use the following code:
e.Graphics.DrawRectangle( redPen, 30, 20, 60, 40)
If you want to draw a filled shape, you will need to use a brush instead of a pen. You can choose from a SolidBrush, which draws in a solid color, a TextureBrush, which draws using a texture defined by a bitmap file, or a LinearGradientBrush, which draws using a defined color gradient.
This is just a brief introduction to GDI and GDI+. GDI+ is a large library with a number of very powerful classes you can use to create and manipulate graphics in your application.
Learn more about this author, Rachelle Reese.
Click here to send this author comments or questions.
Below are the top articles rated and ranked by Helium members on:
by Cobor
The Graphics Device Interface (GDI), together with the kernel and the Windows API, is one of three main components or "sub",
THIs is a newbie guide to GDI. GDI is graphics device interface. This is the interfasce through which we output graphics.
The graphics device interface is basically instructions that produce output graphics: it allows the Windows operating system
GDI (Graphic Device Interface)is one of three core components of Microsoft Windows. It is crucial for anything visual, such
by prime-Hm
GDI is nothing but Graphic Device Interface.
In window system you need GDI to control the display of text and graphics.
You
View All Articles on:
What is graphic device interface (GDI)?
Add your voice
Know something about What is graphic device interface (GDI)??
We want to hear your view.
Write now!
Cast your vote!
Click for your side.
Featured Partner
International Campaign for Tibet (ICT)
International Campaign for Tibet (ICT) has partnered with Helium, giving you the chance to write for a cause. Br...more
hide