![]() |
BitBlt Tutorial
4 Attachment(s)
Hey All i noticed there was no tutorial on this forum for BiBlt so here one I made
Comments and improvements are welcome So you want to learn BitBlt but dont know where to start? Well hopefully this tutorial will get you on the road to becoming a BitBlt master So what is BitBlt? Well BitBlt is one of many windows API's and if your not sure on what or how to use API's then take a look at Optikal And Banjo's tutorial (http://www.xtremevbtalk.com/showthre...&highlight=api) Getting Started So lets jump right in and get some coding done Ok first things first open up a new VB project and we are going to add a module, name it 'mdlBitblt' and name the form 'frmbitblt' In the module we are going to place the BitBlt API so in the module enter the following... Code:
Ok dont be put off bye the way it looks, it looks ALOT harder than it actually is! Next Stage ;) So we have the API in place now all we need to do is use it As you will see I have attached 3 pictures, Hero, Hero Mask, and Land You will need to draw up 3 picture boxes on your form and call them the following Hero HeroMask Land Set the 'autoredraw' property to True, and the 'visible' property to false, it is also a good idea to set the 'scalemode' to 3 – Pixels (also set the forms 'scalemode' to pixels) Ok now into each picture box load its respective image Next draw 3 command buttons and add the following names and captions – Name = cmddrawland caption = Draw Land Name = cmddrawmask caption = Draw Mask Name = cmddrawhero caption = Draw Hero Were all set up now all we need is the code The Land Code we will start by drawing the land.... Code:
In the module… Code:
Ok so lets go through that code…. BitBlt - is saying we want to use the BitBlt Api, frmBitBlt.hDC - is where we are going to BitBlt to, 50 is the X position on the surface your are BitBlt'ing on 50 is the Y position on the surface your are BitBlt'ing on 300 is the width 300 is the height frmbitblt.land.hDC this is what we are actually going to Copy from 0 and 0 - this is the area of the picture u wish to ‘cut out’ for now don’t worry about this VBSrcCopy - this is the type of bitblt for the background we will just copy it! You may have noticed this .HDC well heres a definition... This is an upgrade from previous versions of Visual Basic which allows you to interface with the windows api functions. You will find it on certain controls and all forms as the property .hdc or even hWnd. The term hdc is the handle to the device context of that window or control. The Hero Mask Code And Now we will draw our Hero Mask.... But what is a mask? Well a mask in terms of BitBlt is basicly a copy of the actuall image, in our case all black, which we put on the background first to stop the background colours leaking through and spoiling our image :) Code:
In the module…. Code:
The only differance in the one above is vbSrcAnd which is what we use for masking The Hero Code And now we will draw our hero on top of the mask.... Code:
In the module…. Code:
Again this time we have vbSrcPaint which is what we use for painting on top of the mask! Please make a note to the fact that the hero mask X and Y position must be exactly the same as the Hero’s X and Y :) And that’s it I hope you have now begin to understand how powerfull BitBlt can be I have also made an example in the Zip file below :) Thanks go to IcePlug ‘Good Luck’ PINO- Please note the image of the 'hero' is not made by me, i found while searching, if you are the owner and do not wish me to use it then please say and i will remove it :) |
OK, first you're going to have to spell 'tutorial' correctly. ;)
Quote:
(Just one of the questions that may result... Others below) What's a mask/masking? ... comments Quote:
"Please make a note to the fact that the hero mask X and Y position must be exactly the same as the Hero’s X and Y" Seems like you should actually mention that you are using transparency. Also, those button_click routines should probably be private, but I don't think it would be too much of a problem. You may want to define an hDC and why BitBlt has to use that. :) |
Thank-You for your constructive feed-back :)
I think I have covered all your points... Thanks Again |
How about some continuation on those long lines so it all fits on the screen?
(I fixed the spelling of Tutorial for you, by the way) |
Just for you reboot ;)
thanks :), I fixed a few of the spelling errors :/ but thanks :) |
Sorry to "plug" my own tutorial here, but I have written a three-part GDI tutorial series which you might want to check out, available at EliteVB:
GDI32 Programming Part I: Introduction GDI32 Programming Part II: Pens and Brushes GDI32 Programming Part III: Bit Block Transfer (BitBlt) Your tutorial is good, though you might want to take some more time to explain the "hows and whys" of the way it works. Maybe even split it into multiple parts, as I have done. |
| All times are GMT -6. The time now is 10:16 AM. |
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2007 iNET Interactive and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.