GDI+ Objects: Bitmaps |
|
To support bitmaps, GDI+ provides the Bitmap class. The Bitmap class is based on the abstract Image class. If you have created a bitmap and stored it as a file, you can pass the path of that file to the following constructor of the class:
Public Sub New(ByVal filename As String)
Once the picture is ready, to present it to the user, you can call the Graphics.DrawImage() method that is overloaded with as many different versions as you can possibly need. One of the versions of this method has the following syntax:
Overloads Public Sub DrawImage( ByVal image As Image, ByVal point As Point)
The first argument can be a bitmap that you can have previously initialized. The second argument specifies the location where the picture will be drawn, which will be the top-left corner of the picture with regards to its parent.
Here is an example:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim bmpHorse As Bitmap = New Bitmap("Horse.bmp") e.Graphics.DrawImage(bmpHorse , 20, 10) End Sub |
Practical Learning: Displaying a Bitmap |
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim butterfly As Bitmap = New Bitmap("Butterfly.bmp") e.Graphics.DrawImage(butterfly, 10, 10) End Sub |
|
||
Previous | Copyright © 2004-2010 FunctionX, Inc. | |
|