Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


GDI+ for Beginners #1 filter_list
Author
Message
GDI+ for Beginners #1 #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) ?
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.

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.
- Wikipedia

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
Declares "g" as graphics.

Code:
Dim myString As String
Declares "myString".
This will tell the application what to write in the location you have selected.

Code:
Dim myFont = New Font
Declares "myFont".
The text (myString) will we displayed with the font/font-style you chose.

Code:
g.DrawString
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:

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
Declares "g" as graphics.

Code:
Dim myBitmap As Bitmap
Tells the application what path the image you want to be drawn.

Code:
g.DrawImage(myBitmap, 1, 1)
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
[Image: tumblr_m4vms28lYu1qj3ir1.gif]

Reply

RE: GDI+ for Beginners #1 #2
Oh so that's what you meant with GDI on Skype haha ^^ Yes I know GDI, good #1 tutorial btw!

Reply

RE: GDI+ for Beginners #1 #3
(07-30-2013, 05:59 PM)Platinum Wrote: Oh so that's what you meant with GDI on Skype haha ^^ Yes I know GDI, good #1 tutorial btw!

Thanks mate Smile
PM me on Skype!
[Image: tumblr_m4vms28lYu1qj3ir1.gif]

Reply

RE: GDI+ for Beginners #1 #4
Nice tutorial, Explained ok but could've been better. I suggest making a tutorial on how to create themes in GDI.

Reply

RE: GDI+ for Beginners #1 #5
This is a pretty nice tutorial! Good job, Son! Also, I agree with Tiger on the theme part. Biggrin
[Image: WV5eQ42.jpg]

If you've got any questions regarding c++ or java, feel free to hit me up with a private message at any time.

http://adf.ly/UyTEk

Reply

RE: GDI+ for Beginners #1 #6
Pretty good tutorial Eternity, GDI+ is extremely easy to get a hang of. I remember back about 2 months ago I was on join.me with Mavamaarten (A professional theme designer) watching him make a new theme, I really learned a lot from that session, watching the same code being repeated multiple times will get stuck in your head easily. Anyways good job Tongue.
[Image: OkXCq.gif]

Reply

RE: GDI+ for Beginners #1 #7
(08-04-2013, 05:24 AM)#Tiger Wrote: Nice tutorial, Explained ok but could've been better. I suggest making a tutorial on how to create themes in GDI.

I doubt i will ever create a Theme tutorial since i don't see any use of them when you can use GDI+ + images on the form.

(08-04-2013, 10:11 AM)Xiledcore Wrote: This is a pretty nice tutorial! Good job, Son! Also, I agree with Tiger on the theme part. Biggrin
Thanks father!
(08-04-2013, 10:36 AM)Hexology Wrote: Pretty good tutorial Eternity, GDI+ is extremely easy to get a hang of. I remember back about 2 months ago I was on join.me with Mavamaarten (A professional theme designer) watching him make a new theme, I really learned a lot from that session, watching the same code being repeated multiple times will get stuck in your head easily. Anyways good job Tongue.

You're right, GDI+ is extremly easy to get a hang of.
Started with it last week i think, before that i was scared to try it since I've seen code snippets on how "hard" it was.

Thanks
[Image: tumblr_m4vms28lYu1qj3ir1.gif]

Reply







Users browsing this thread: 1 Guest(s)