|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Lets see an example to show how the Picture object works. First, we create a Picture object, picObject1:
Private Sub Command1_Click()
Dim picObject1 As Picture
End Sub
Then we load the image into that Picture object using LoadPicture:
Private Sub Command1_Click()
Dim picObject1 As Picture
Set picObject1 = LoadPicture("c:\image.bmp")
End Sub
Finally, we just set a picture boxs Picture property to the Picture object, and thats it:
Private Sub Command1_Click()
Dim picObject1 As Picture
Set picObject1 = LoadPicture("c:\image.bmp")
Set Picture1.Picture = picObject1
End Sub
You can also use the Render method to draw images with the Picture object (although PaintPicture is Microsofts preferred method these days). The Render Method Heres how you use the Render method to draw images with the Picture object:
PictureObject.Render (hdc, xdest, ydest, destwid, desthgt, xsrc, ysrc, _
srcwid, srchgt, wbounds)
Here are what the arguments for Render mean:
Using Arrays Of Picture ObjectsYou can use an array of Picture objects to keep a series of graphics in memory without using a form that contains multiple picture box or image controls. This is good for creating animation sequences or other applications where rapid image changes are required. Lets see an example. Here, well create an array of Picture objects and load images into them. We start by setting up an array of two Picture objects as a form-wide array: Dim picObjects(1 To 2) As Picture Then when the form loads, we read in two image files into the array:
Private Sub Form_Load()
Set picObjects(1) = LoadPicture("c:\vbbb\pictureanimation\image1.bmp")
Set picObjects(2) = LoadPicture("c:\vbbb\pictureanimation\image2.bmp")
End Sub
Now the images in the array will be available for use in our program (and well use them in a later topic in this chaptersee Creating Image Animation). Adding Picture Clip Controls To A ProgramOne way of storing images in a Visual Basic program is to use a picture clip control. This control stores a number of images as one large bitmap, and to get the image you want, you have to clip it out of that bitmap. If that sounds a little less convenient to you than using an image list control or array of Picture objects, youre rightit is. Picture clips were first made available long ago in Visual Basic and dont support all the convenience of more modern controls. However, programmers still use them, and well cover them here.
To add a picture clip control to a program, follow these steps:
Now we add an image that consists of three images added together to the picture clip control, as you can see in Figure 19.5. When you want to get a picture from a picture clip control, you specify the (x, y) coordinates of the bitmap section you want, and its height and width. You can also divide the image up into rows and columns, as well see in a few topics.
To put the picture clip control to work, see the next few topics in this chapter. Selecting Images In A Picture Clip Control Using CoordinatesYouve placed all the images you want to store into a picture clip control as one large bitmap. How can you get your images back out again? There are two ways to get images out of a picture clip control (three, if you count accessing the whole bitmap with the controls Picture property): by specifying the images coordinates in the whole bitmap, or by breaking the bitmap into rows and columns and accessing the image by row and column. After you specify an image, you can retrieve it using the picture clips Clip property. Well see how to use bitmap coordinates in this topic, and rows and columns in the next topic.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |