| Index |
There are many tutorials over
the internet about the BitBlt API call. This is one of the most
The BitBlt function resides in GDI32 (graphics device interface), a dll that is usually located at your system path. It is used to print rectangular blocks of pixels from a source image (that can be either in a picture box or stored at a memory DC) to a destination (the same thing). Well, if you didn't understand too much, just think of BitBlt as a function similar to PaintPicture - but with much more effects and velocity. To call this function from VB, add the following code to the declarations section of a module:
Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long ' ================================
' ByVal
hDestDC As Long ..... hDC of object to receive the .bmp
Here it is! Now that you have declared the function, add some constants to the raster operations you'll use:
Public Const SRCCOPY = &HCC0020 'Copies the source bitmap to destination bitmap. Public Const SRCAND
= &H8800C6
'Combines pixels of the destination with source bitmap
Public Const DSINVERT = &H550009 'Inverts the destination bitmap. Public Const NOTSRCCOPY = &H330008 'Copies the inverted source bitmap to the dest. Public
Const NOTSRCERASE
= &H1100A6 'Inverts the result of combining
the destination and
Public
Const MERGEPAINT = &HBB0226
'Combines the inverted source bitmap with the
Public
Const PATINVERT
= &H5A0049 'Combines the destination
bitmap with the pattern
Public
Const PATPAINT
= &HFB0A09 'Combines
the inverted source bitmap with the pattern
Public Const WHITENESS = &HFF0062 'Turns all output white. Public Const BLACKNESS = &H42 'Turn output black.
With this you have all the possibilities that can be used with the BitBlt function. Now we can proceed... If you examined the code well, you must have noticed two little tricky parameters: hDestDC and hSrcDC. These properties are handles Windows use to identify where are the source and destination pixels. Device Contexts are utilized in almost all API calls - just take a look over VB Center and you'll see other functions that use DCs. Forms and PictureBoxes already have their hDC property so that you can perform graphics-related functions. Ok. So when you use BitBlt, it will be like this: BitBlt to Destination.hDC , (additional parameters), from Source.hDC Another thing: you must set your Forms and PictureBoxes AutoRedraw property to True, and after you blit, Refresh your control (object.Refresh). The best way to learn is looking
at examples, so pay attention to the following:
Look at the example above with attention. I'm sure you understand something! If you have any questions, e-mail me! Check our tutorial on acheiving transparency and on the creation of DCs soon!
|