GDI+ for Beginners #1 07-30-2013, 04:48 PM
#1
This is the first of hopefully many tutorials on GDI+.
I will go more in depth in the later tutorials since this is just the basic and i don't see how anyone will benefit anymore if i went deeper.
1. What is GDI+ (The Graphics Device Interface) ?
Now that you know what GDI is let's start with the coding.
2. Display Text
Add a button to your form or function and input the following Code:
A) Explaination
Declares "g" as graphics.
Declares "myString".
This will tell the application what to write in the location you have selected.
Declares "myFont".
The text (myString) will we displayed with the font/font-style you chose.
Draws the string to the location you've selected with the text,font,font-style and location inside the the control(Form) you've selected.
B) Use
g.DrawString("Text here or string name", "Font here or font variable name here", "Color here", "Location. 14, 15")
3. Draw Bitmap
Add a button to your form or function and input the following Code:
A) Explaination
Declares "g" as graphics.
Tells the application what path the image you want to be drawn.
Draws the image to the location you've selected with the image and location inside the the control(Form) you've selected.
B) Use
g.DrawImage("Image Path", "Image Location")
Download the whole project here with compiled and un-compiled version from MediaFire.
Virus Scan(VirusTotal)
Detection ratio: 0 / 46
I will go more in depth in the later tutorials since this is just the basic and i don't see how anyone will benefit anymore if i went deeper.
1. What is GDI+ (The Graphics Device Interface) ?
Quote:The Graphics Device Interface (GDI) is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers.- Wikipedia
GDI is responsible for tasks such as drawing lines and curves, rendering fonts and handling palettes. It is not directly responsible for drawing windows, menus, etc.; that task is reserved for the user subsystem, which resides in user32.dll and is built atop GDI. Other systems have components that are similar to GDI, for example Macintosh's Quartz (originally QuickDraw) and GTK's GDK/Xlib.
GDI's most significant advantages over more direct methods of accessing the hardware are perhaps its scaling capabilities and its abstract representation of target devices. Using GDI, it is very easy to draw on multiple devices, such as a screen and a printer, and expect proper reproduction in each case. This capability is at the center of all What You See Is What You Get applications for Microsoft Windows.
Simple games that do not require fast graphics rendering may use GDI. However, GDI is relatively hard to use for advanced animation, and lacks a notion for synchronizing with individual video frames in the video card, lacks hardware rasterization for 3D, etc. Modern games usually use DirectX or OpenGL instead, which let programmers exploit the features of modern hardware.
Now that you know what GDI is let's start with the coding.
2. Display Text
Add a button to your form or function and input the following Code:
Code:
Dim g As Graphics = PictureBox1.CreateGraphics 'Where to display the text(Can be in a form also).
Dim myString As String = "I like GDI+ !" ' The text you want to display.
Dim myFont = New Font("Arial", 24, FontStyle.Regular) ' What font and style you want to display the text as.
g.DrawString(myString, myFont, Brushes.Black, 1, 1) ' Draws everything. "Brushes.Black" Is the color of the text and "1, 1" is the location.
A) Explaination
Code:
Dim g As Graphics
Code:
Dim myString As String
This will tell the application what to write in the location you have selected.
Code:
Dim myFont = New Font
The text (myString) will we displayed with the font/font-style you chose.
Code:
g.DrawString
B) Use
g.DrawString("Text here or string name", "Font here or font variable name here", "Color here", "Location. 14, 15")
3. Draw Bitmap
Add a button to your form or function and input the following Code:
Code:
Dim g As Graphics = PictureBox2.CreateGraphics ' Where to display the image.
Dim myBitmap As Bitmap = My.Resources.Cat_image ' What image to display.
g.DrawImage(myBitmap, 1, 1) ' Draws the image "(1,1)" is the location.
A) Explaination
Code:
Dim g As Graphics
Code:
Dim myBitmap As Bitmap
Code:
g.DrawImage(myBitmap, 1, 1)
B) Use
g.DrawImage("Image Path", "Image Location")
Download the whole project here with compiled and un-compiled version from MediaFire.
Virus Scan(VirusTotal)
Detection ratio: 0 / 46
![[Image: tumblr_m4vms28lYu1qj3ir1.gif]](http://media.tumblr.com/tumblr_m4vms28lYu1qj3ir1.gif)