|
_ TUTORIAL: BitBlt & GDI32 for the Thick-Headed: BitBlt explained, + Load Sprites, Double Buffering!
|
Email
|
| Submitted on: |
6/20/2002 2:28:44 AM |
| By: |
(Tim Miron) yar-interactive software
|
| Level: |
Intermediate |
| User Rating: |
By 70 Users |
| Compatibility: |
VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script |
| Views: |
92823 |
|
(About the author) |
|
|
|
"BitBlt [and GDI32] for the Thick Headed" is an in-depth, plain-english, streight-forward tutorial that teaches everything there is to know about BitBlt, and some related API. It covers everything from loading bitmap files into memory (no more picture boxes) to double-buffering (say goodbye to the SLOW 'AutoRedraw'!) to Explaining the BitBlt API in PLAIN ENGLISH. PLUS the tutorial only takes about 15 to 20 minutes to complete! (A completed version of the example project is also included)
This article has accompanying files
|
| |
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
BitBlt for the Thick-Headed...
In this tutorial you will learn...
- Howto load a bitmap file into memory
- Howto create a back-buffer
- The BitBlt API explained in plain english
- Howto use double-buffering techniques to achieve fast, flickerless graphics (faster then AutoRedraw)
This tutorial should NOT take more then 15 minutes to read - If you read every line and follow every instruction, almost everything you need to know [about BitBlt] is here!
Welcome to my tutorial which I have titled BitBlt for the Thick Headed. If you want to go through this tutorial quickly, all the essential parts are in BOLD. For the record, I mean no offence to anyone on the PSC community, I was going to call it BitBlt for Dummies like the popular For Dummies books, but didn't want to get into copyright complications with book publishers. The goal of this tutorial is to step-by-step explain howto use BitBlt and some other Win32 GDI functions, to accomplish tasks such as double buffering and loading sprites from files - All in a relatively short reading-time (basically i'll try not to ramble on too much)
Anyways, let's get started...
The first thing your going to do obviously is create a form (so you can follow along with this tutorial), set the ScaleMode to '3 - Pixel', I suggest you always set the scalemode to Pixels if your going to be using the form with API.
Next Increase the form's size until the ScaleWidth is 320, and the ScaleHeight is 256.
We will be using the form as our practice surface, note that the form property called "HasDC" must be set to TRUE. Also, for many of you who fell in love with using AutoRedraw, we will NOT need AutoRedraw because we are going to be using Double Buffering which is ALOT faster, and more professional.
The next step is to declare the API calls that we will need, as shown below. So copy and paste the code below into your form. If you dont know what API is, then you should do some research about it, before you even try to figure this tutorial out! ;-)
'The following API calls are for:
'blitting
Private Declare Function BitBlt Lib "gdi32" (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
'code timer
Private Declare Function GetTickCount Lib "kernel32" () As Long
'creating buffers / loading sprites
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
'loading sprites
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
'cleanup
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
'end of copy-paste here...
|
Q. What is a DC (also known as: Device Context, hDC)?
A. A Device Context is a number that points to an "address" in memory where data is stored, when using BitBlt, we point to the Address where graphical data is stored in memory.
Next, we need to store the addresses of the DC's that we are creating. DC's addresses are Long values so we will Declare Public Variables to store the DC's memory address as shown below. (copy and paste
'our Buffer's DC
Public myBackBuffer As Long
Public myBufferBMP As Long
'The DC of our sprite/graphic
Public mySprite As Long
'coordinates of our sprite/graphic on the screen
Public SpriteX As Long
Public SpriteY As Long
'end of copy-paste here...
|
Q. Do we have to make all these variable's public?
A. NO, BUT its a good idea to at least make the DC's variables public so that its easier to cleanup the memory after the program is finished.
Now we have the foundation of our code, we have all the API declarations we'll be needing, and all the variables we'll be using in this example. The next thing we're gunna do is create a function that loads graphics into memory, it makes working with the API a bit simpler...
Device Contexts - TIP: One thing that is important to understand is that a device context alone has no graphical data in it. A device context needs to have a bitmap loaded into it, whether that be a bitmap file, or a blank bitmap to use as a canvas to draw on (which is how you create a back buffer).
Ok, so this is what our function does... It creates a Device Context compatible with the screen, it then loads the specified graphics file into the device context... Copy and paste the function below, but be sure to read all the comments so you understance the concept.
Public Function LoadGraphicDC(sFileName As String) As Long
'cheap error handling
On Error Resume Next
'temp variable to hold our DC address
Dim LoadGraphicDCTEMP As Long
'create the DC address compatible with
'the DC of the screen
LoadGraphicDCTEMP = CreateCompatibleDC(GetDC(0))
'load the graphic file into the DC...
SelectObject LoadGraphicDCTEMP, LoadPicture(sFileName)
'return the address of the file
LoadGraphicDC = LoadGraphicDCTEMP
End Function
'end of copy-paste here...
|
Q. What is double-buffering?
A. Double Buffering is when you create a graphical surface to paint on (like a canvas) that you blit all of your sprites/graphics/text onto in the memory (offscreen) then blit the final result onto the screen. It prevents flickering (which occurs if multiple sprites are blitted directly onto the screen.) and is much faster then AutoRedraw.
We're gunna be using the function in our example code... but before we go any further with the example project, I'm going to explain the BitBlt API from start to finish.
The BitBlt API...
BitBlt is a function in the DLL "gdi32".
Technical Deffinition: it performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
In Plain English... This basically means that it copys graphical data from one graphics surface [a bitmap] to another graphics surface [the screen, or a form].
Now lets take a look at the API declaration itself...
The API declaration should be placed in the "General Declarations" section of a form or module. Here's what it looks like:
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
The first part of this code, the first line (in this example) says that we're
accessing the BitBlt function from the gdi32 DLL. the following lines are parameters that we have to input in order to use the function in our program. Here's a rundown of what each of these parameters is:
hDestDC - The hDC of the destination surface (this could be a form.hDC if you want to blit to a form, or it could be the address of a backbuffer that we've created).
x - The X (horizontal position) coordinate of where we want the graphic to appear.
y - The Y (vertical position) coordinate of where we want the graphic to appear.
nWidth - The width of our graphic.
nHeight - The height of our graphic.
hSrcDC - The hDC of the source graphic, for example the DC address of a sprite that we loaded into memory.
xSrc - The X (horizontal) offset, 0 if you want to blit from the very left edge of the source graphic, if you want to start the blit from 18 and over then you would make this value 18, etc.
ySrc - The Y (vertical) offset, same idea as xSrc, except vertically
dwRop - The drawmode we want to use when blitting our graphic, also known as Raster Operations or ROPs. This parameter is explained below.
The drawmodes, or Raster Operations/ROPs available are as follows, each of these is a reserved constant in VB, so any one of these words (in italic) can be used in the dwRop parameter to acheive different effects:
<-- Blt Modes -->
- vbSrcCopy - Copy the source image data directly onto the destination,
replacing it completely.
- vbSrcPaint - ORs the source and destination image data, giving a
pseudo-alphablending effect.
- vbSrcAnd - ANDs the source and destination image data, giving a
pseudo-gamma effect.
- vbSrcInvert - XORs the source and destination image data.
- vbSrcErase - Inverts the destination image data then ANDs with
the source image data.
- vbDstInvert - Inverts the destination image data, and ignores the
source image data completely.
- vbNotSrcCopy - Inverts the source image data and copies directly onto
the destination, replacing it completely.
- vbNotSrcErase - ORs the source and destination image data and
inverts the result.
'An example of using BitBlt
BitBlt Form1.hDC, PlayerX, PlayerY, 48, 48, picPlayer.hDC, 0, 0, vbSrcCopy
On with our example project...
Next in our example project (this is the final part), we're going to use BitBlt in a loop much like you would in a game. Here's what you need to do:
- Save the project file (and form file) in its own Directory.
- Create a bitmap (BMP) file, make it 32 X 32 pixels. And save it in the same directory as the project.
- NAME THE BMP FILE "sprite1.bmp"
- Create a command button, rename it to cmdTest.
- Move the command button to the bottom right of the form.
- Double click on the command button to bring-up its sub in the code-window, so we can enter code to be executed when it is pushed.
Copy and paste this code into the command button's Click-Event subroutine.
READ ALL THE COMMENTS, to understand the code...
'=== THIS CODE GOES IN CMDTEXT_CLICK EVENT ===
'Timer variables...
Dim T1 As Long, T2 As Long
'create a compatable DC for the back buffer..
myBackBuffer = CreateCompatibleDC(GetDC(0))
'create a compatible bitmap surface for the DC
'that is the size of our form.. (320 X 256)
'NOTE - the bitmap will act as the actual graphics surface inside the DC
'because without a bitmap in the DC, the DC cannot hold graphical data..
myBufferBMP = CreateCompatibleBitmap(GetDC(0), 320, 256)
'final step of making the back buffer...
'load our created blank bitmap surface into our buffer
'(this will be used as our canvas to draw-on off screen)
SelectObject myBackBuffer, myBufferBMP
'before we can blit to the buffer, we should fill it with black
BitBlt myBackBuffer, 0, 0, 320, 256, 0, 0, 0, vbWhiteness
'load our sprite (using the function we made)
mySprite = LoadGraphicDC(App.Path & "\sprite1.bmp")
'MsgBox Dir$(App.Path & "\sprite1.bmp")
'ok now all the graphics are loaded so
'lets start our main loop..
'Disable cmdTest, because if the graphics are
'reloaded there will be memory leaks...
cmdTest.Enabled = False
'== START MAIN LOOP ==
'get current tickcount (this is used as a code timer)
T2 = GetTickCount
Do
DoEvents 'DoEvents makes sure that our mouse and keyboard dont freeze-up
T1 = GetTickCount
'if 15MS has gone by, execute our next frame
If (T1 - T2) >= 15 Then
'clear the place where the sprite used to be...
'(we do this by filling in the old sprites place
'with black... but in games you'll probably have
'a background tile that you would blit here)
BitBlt myBackBuffer, SpriteX - 1, SpriteY - 1, _
32, 32, 0, 0, 0, vbBlackness
'blit sprites to the back-buffer ***
'You could blit multiple sprites to the backbuffer,
'but in our example we only blit on...
BitBlt myBackBuffer, SpriteX, SpriteY, 32, 32, _
mySprite, 0, 0, vbSrcPaint
'now blit the backbuffer to the form...
BitBlt Me.hdc, 0, 0, 320, 256, myBackBuffer, _
0, 0, vbSrcCopy
'move our sprite down on a diagonal...
'Me.Caption = SpriteX & ", " & SpriteY
SpriteX = SpriteX + 1
SpriteY = SpriteY + 1
'update timer
T2 = GetTickCount
End If
'loop it until our sprite is off the screen...
Loop Until SpriteX = 320
'end of copy-paste here...
|
DONT RUN THE PROGRAM YET, we need to write the cleanup code...
The cleanup code is just some code that we add that clears the memory that was occupied by the graphics that we loaded, and the backbuffer that we created (see above code).
This code should usually go in the Form_Unload event, so that it is executed when the form unloads...
Copy and Paste the code below into the form's module
Private Sub Form_Unload(Cancel As Integer)
'this clears up the memory we used to hold
'the graphics and the buffers we made
'Delete the bitmap surface that was in the backbuffer
DeleteObject myBufferBMP
'Delete the backbuffer HDC
DeleteDC myBackBuffer
'Delete the Sprite/Graphic HDC
DeleteDC mySprite
End
End Sub
'end of copy-paste here...
|
That's it! We're done! Run the program, click the button and you will see the sprite move from the top-left of the form to the bottom right, without any flickering...
Example project included.
yar interactive software - 2002
|
|
Download article
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
- Re-scan downloaded files using your personal virus checker before using it.
- NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
- Scan the source code with Minnow's Project Scanner
If you don't have a virus scanner, you can get one at many places on the net
including:McAfee.com
|
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
Other 18 submission(s) by this author
|
|
Report Bad Submission
|
Your Vote
|
| |
Other User Comments
|
6/20/2002 10:59:56 AM: (Tim Miron) yar-interactive software
I think I'll submit an updated version of this article making some corrections, and also add info about Transparent Blitting meathods etc. (If this comment was disrespectful, please report it.)
|
6/21/2002 4:40:54 AM: Martin
Good job Tim. It's not easy writing tutorials there'll always be someone who either doesn't understand it or can find faults in it. Keep up the good work - if you want to write this sort of article PSC is good place to hone your skills. I'll look forward to another tut from you soon. Good luck. (If this comment was disrespectful, please report it.)
|
6/21/2002 6:25:43 AM: dafhi
Tim I wanted to say thanks again for posting this article. To even get me to paste code with BitBlt in it is a major biggie. This is a fun project and it really does take 15 minutes or less. Not to mention the friendly and professional layout of this article.. (If this comment was disrespectful, please report it.)
|
7/5/2002 8:35:20 AM:
nice (If this comment was disrespectful, please report it.)
|
7/16/2002 10:38:06 PM: Mr_Tuna
That was incredible, especially for me because i am new to this idea and have been working on visual basic for a good period of time. This is great for all beginners. I have been trying to make an arcade style shoot 'em game up like space invaders or so, and i have been working on that idea for months and not being able to do it. now i think that i have the knowledge to start really gettings things goin. Again, thanks a whole lot for you tutorial, keep up the great work, and next time i'll vote. Great Job! -Mr_Tuna-
(If this comment was disrespectful, please report it.)
|
7/20/2002 1:41:59 AM: alfadog
Excellent! This code taught me what was going through the API designers' heads so that I can use their interfaces now! Thanks a million. (If this comment was disrespectful, please report it.)
|
8/23/2002 1:53:24 PM: Neal Blair
This is wonderful. Your tutorial was extremely helpful for the creation of a program I just posted. Thank you. (If this comment was disrespectful, please report it.)
|
9/7/2002 8:28:00 PM:
Nice tutorial (If this comment was disrespectful, please report it.)
|
9/22/2002 11:58:57 AM: Rob Loach
Could you put a mask in? I'm having some troubles with rendering multiple Sprites with Masks onto a ready rendered background. (If this comment was disrespectful, please report it.)
|
9/24/2002 4:19:58 AM: zeff calilung
hello. could you help me. i made a client server program. i want to capture my desktop in the client side and send it to the picture box in the server side of my program. how could i do that with out saving the file and transfering ito the server. (If this comment was disrespectful, please report it.)
|
10/9/2002 4:33:33 AM: apidude
great tutorial, easy to follow & understand
thank you sir! (If this comment was disrespectful, please report it.)
|
10/9/2002 7:28:57 AM: David Irvine
this tutorial has helped alot, i just couldn't get the double buffering process to work last time but now i understand.Thanks again! (If this comment was disrespectful, please report it.)
|
11/2/2002 2:58:16 PM:
Fantastic tutorial! I wish I'd found this before I managed to piece together a lot about BitBlt from a ton of different bad tutorials! Still, it was very informative to me. ^_^ Thank you, keep up the good work~ (If this comment was disrespectful, please report it.)
|
11/3/2002 10:53:46 AM:
Sound example, i have been not found any more tutorials as good as this one, Thanks for the help..
(If this comment was disrespectful, please report it.)
|
11/8/2002 2:00:05 AM:
You have cured me of something that's been nagging in my head for a long time. Now I feel relieved and have a huge chore behind me. Now, after reading your great tutorial, these questions come to mind. How can I construct an array whose pointer I send directly into BitBlt, this will not only increase the scope of my creativity but will also aleviate a problem that VB has with multi-threading; as noted by a poster above whose having problems getting simultaneous action going. And why doesn't the image appear on the screen immediately after I use BitBlt; how does this work that placing a form HDC draws the image on the screen; what drawing powers does the form(windows) have that's not in our reach and why can't we tap into them and; I guess that's it for now. I think we all share the same views that's what's limiting our creative potential is the simple stuff hidden from us by Windows which could give us a tap into the tremendous power of our hardware. Thank You again. (If this comment was disrespectful, please report it.)
|
11/8/2002 4:02:35 PM: Rob Loach
Dear previous poster, You should be a novelist :P. (If this comment was disrespectful, please report it.)
|
11/11/2002 12:03:30 PM:
Thanks, and I plan to partially be one. Let me just clarify my previous post. When you load a bitmap, all that you are essentially doing is loading an array of numbers. The way this array works is unbeknown to me. Now, if I had a desire to create dynamic images, which I do, it would be impossible to do them using predefined bitmaps. I like and want to have control over the individual pixels. Now your instantaneous thought should be that I should go into OpenGL and DirectX; and this is what I plan to do, in addition to Visual C++. Somehow, after visiting this site, I found myself viewing OpenGL pages and the amount of info and details about creating games using it inspired me to go into it. (If this comment was disrespectful, please report it.)
|
11/15/2002 1:57:58 AM:
That's a good tutorial. One question though.. Why is your website linked to a porno site? (If this comment was disrespectful, please report it.)
|
11/16/2002 11:09:53 AM:
looooooooooooooooooool linked to a porno site :D good tut. though.. must've taken ages to write everything (If this comment was disrespectful, please report it.)
|
1/18/2003 8:44:29 AM:
Hi, I've not tried to complete this tutorial, but I'm sure it'll come in handy. Thanks for writing the tutorial because I've been wondering on how to animate graphics without the flickering and without using DirectDraw. Keep up the good work. (If this comment was disrespectful, please report it.)
|
1/20/2003 2:47:34 PM:
I like your tutorial very much! It really helped. (Not to mention the fact that it shows how to use BitBlt properly...) (Most people using Bitblt for RPGs load tile blocks into picture boxes and bitblt from those.(Yuck!)) One question: I made the back buffer 1024x1024 and made my viewing window 320*200. I am using it as a scrolling background on a Red Aleart clone. If I make the back buffer HUGE (4024x4024) it doesn't work. Do you know what the max size is? Is it related to the amount of video memory?
Thanks much! (If this comment was disrespectful, please report it.)
|
1/28/2003 9:17:48 AM: Joseph Hicks
First off, great tut (like THAT'S original!). Second, I would like to suggest that you take some(all?) of the questions in here and answer them in a FAQ-type-manner and distribute it to your mailing list. Thanks again. :) (If this comment was disrespectful, please report it.)
|
1/28/2003 1:10:59 PM: SkinRock
Great tutorial, I've been waiting for a good one on BitBlt. I too am trying to make this into a map scrolling type game. So far everything has been nice to me, I rewrote some code so that the bmp moves according to mouse postion (all 8 sides actually), but now I don't know how to do a loop that will keep moving the bmp while you are in that area. Basically I just put the rendering code in the mouse move sub, and took out the timer vars and movement calls, and added some if statements checking to see where the mouse is, and if it is in one of the 4 sides or 4 corners, it will move, but only once. (If this comment was disrespectful, please report it.)
|
1/28/2003 4:31:01 PM: (Tim Miron) yar-interactive software
RE: Joe Hicks, I will deffinitly do that, a few of you have recently joined the mailing list, if anyone else would like to, send an e-mail to timbo_m45@hotmail.com and make the subject "mailing list".
For further reading on VB game development, I suggest seeing http://vbgamer.strategon.com (If this comment was disrespectful, please report it.)
|
2/4/2003 4:46:10 PM:
THANK YOU SO MUCH!!!! 5 globes all the way!!!! Thank you so much!!!! (If this comment was disrespectful, please report it.)
|
3/4/2003 3:31:42 AM:
This is wonderful. Your tutorial was extremely helpful (If this comment was disrespectful, please report it.)
|
3/23/2003 10:44:51 PM:
9 months later this code is still helping people like me, thanks (If this comment was disrespectful, please report it.)
|
3/28/2003 9:15:25 PM:
This tutorial is very imformative and useful, infact I continue refering to everytime I work with BitBlt. Great work! (If this comment was disrespectful, please report it.)
|
4/1/2003 12:42:44 PM: (Tim Miron) yar-interactive software
wow.. I'm totally amazed at the response I've gotten on this tutorial.. sorta makes me wanna write another one. What do ya think I should write about next? (try to keep it in the realm f VB game/graphics programming). (If this comment was disrespectful, please report it.)
|
4/2/2003 2:00:46 PM:
I like to see a tutorial about hooking up GDI to capture screen updates. By the way nice work Tim Miron (If this comment was disrespectful, please report it.)
|
4/6/2003 1:18:38 PM:
I would like to see whatever you can put into simple terms about intermediate to advanced game programming, that would be absolutely great! I am looking forward to whatever you come up with. And again thanks a whole bunch, Game programming and bitblt has become very clearer to me because of your article.
-Mr_Tuna- (If this comment was disrespectful, please report it.)
|
9/22/2003 9:18:31 PM: Jay
Well, I have to say. This was absolutely the best tutorial on bitblt I have ever seen. I completely understand it 500x more then I did before. The only thing I ask is that you can possibly in the future add the transparency and maybe background tiling type stuff! Great, great job! (If this comment was disrespectful, please report it.)
|
9/24/2003 1:49:27 PM:
Excellent tutorial, thank you. (If this comment was disrespectful, please report it.)
|
12/24/2003 3:29:06 PM: David Thielke
Wonderful tutorial. Although I already knew most of what there is to know about BitBlt, I still learned a few things, the most helpful being the use of GetTickCount as a more accurate timer. Thanks a lot, and keep up the great work! (If this comment was disrespectful, please report it.)
|
1/1/2004 3:59:06 AM: Jerome A. Simon
Thank You for sharing this tutorial. It was very informative. I will probably be using some of this code in a GameGrid Engine I am trying to create. I just have one 'nag' (sorry) - You should try to never use the "END" command in 'Form' code -> Unload Me (if you have to) (If this comment was disrespectful, please report it.)
|
1/8/2004 12:44:25 AM:
I've always used BitBlt, but never understood the way it worked. Made for a lot of hassle when I wanted to do something that wasn't something I had done before. I love this tutorial, you've done a stellar job. =D
If I were femme I'd want you to be the father of my bebbies. XP (If this comment was disrespectful, please report it.)
|
1/11/2004 12:06:31 AM:
Very very good tutorial. This helped me out a lot understanding it. Anyone who critizes this must be from another planet. Keep up the good work Tim! (If this comment was disrespectful, please report it.)
|
2/4/2004 5:25:33 PM:
wow, ive been using vb for way too long and i didnt even know how to use bitblt, yea, awsome... thnx for the tutorial :) (If this comment was disrespectful, please report it.)
|
2/4/2004 5:28:30 PM:
oh yea, can you add some junk on transparency that would be very helpful, yup...... (If this comment was disrespectful, please report it.)
|
5/21/2004 10:22:49 PM:
great tutorial thanks a lot (If this comment was disrespectful, please report it.)
|
7/25/2004 8:09:32 PM: Asylum]oL[
I read this tutorial two years ago, I think. This was the first thing that used BitBlt that I truly understood what was being talked about. Now it's a no-brainer when I need to do something with GDI32 functions. I'm just comming back to this site and I ran across this tutorial again, and I wanted to thank you. :) (If this comment was disrespectful, please report it.)
|
7/31/2004 3:30:55 PM:
Tim excellent work!! Very well commented, short code and works!! I can't understand why you haven't got award for this, but you should! [votes 5 stars]
Daniel Rapp (If this comment was disrespectful, please report it.)
|
8/15/2004 10:57:19 PM:
I'm pretty sure he did win an award for this. BTW, Tim this is the best BitBlt tutorial I've ever came across and I've came across many, excellent work!! (If this comment was disrespectful, please report it.)
|
8/20/2004 3:34:43 PM: (Tim Miron) yar-interactive software
Thanks for the feedback, it amazes me and inspires me to know my work is still useful two years later! I did not win an award for this submission (I believe it was submitted late in the month), but it is awarding enough to help other people figure things out! I won other awards on PSC anyways! Thanks for the feedback everyone!!! KEEP IT COMMING! =D
PS - if anyone has any questions or comments, feel free to e-mail me at timbo_m45@hotmail.com (If this comment was disrespectful, please report it.)
|
10/26/2004 4:09:00 AM:
The ideas are working good but I have a Problem. I want to capture the image of a combobox from Picturebox1 to PictureBox2. By using this technique with SrcCopy I was able to do that. But during the process,if any other object comes on the combobox. Even that appears in the destination that I dont want. Pls help me out. (If this comment was disrespectful, please report it.)
|
1/23/2005 11:12:27 AM:
Yar Dude cool code Just like your Falldown code in some c++ forum whose name i've forgotten. Great Job (If this comment was disrespectful, please report it.)
|
1/29/2005 3:16:12 AM:
Years later and still helping... Tim, you're a great teacher among programmers everywhere. I remember reading this article when it came out and had to come back for a refresher course. Congratz once again on a excellent job done.
And in case you were wondering, I was the guy with the bebbies comment. 8p (If this comment was disrespectful, please report it.)
|
2/4/2005 8:24:53 AM:
Tim, this is by far the best article I have read so far in my short time at PSC. Not only is it informative but it tackles a difficult and complicated subject (for newbs like me) in a way that is understandable. So many articles I have read have thrown code examples at me without explaining basic principles. I refer of course to your explanation of the bitblt parameters etc. Once again a great article and prog. absolutely top notch mate, keep it up!! (If this comment was disrespectful, please report it.)
|
2/25/2005 11:07:21 PM: CBBibleboy
Hey, I've made a pretty good game using bitblt, but I have a problem. For some reason, when I run the program sometimes it runs at regular speed, sometimes it runs at about 1/3 speed for some reason. I don't know why. If anyone can emil me telling me why, that would be great. I can send the project if needed. (If this comment was disrespectful, please report it.)
|
9/29/2005 2:16:10 AM:
its great,can u help me, my problem is how to do a program that is when the last time i press key or mouse the timer will is start counting and if it meets 10 sec.form 2 will appear.the example is auto log off. (If this comment was disrespectful, please report it.)
|
4/11/2006 9:15:38 PM: Matt Pope
Very nice, Helped me alot :) Thanks. 5 of those little globes for you (If this comment was disrespectful, please report it.)
|
4/19/2006 2:32:56 AM: Patabugen-
Very nice tutorial, have come back looking specifically for it (i forgot everything since i last used bitblt).
Im having a little trouble understanding this bit: myBackBuffer = CreateCompatibleDC(GetDC(0)) myBufferBMP = CreateCompatibleBitmap(GetDC(0), 320, 256) SelectObject myBackBuffer, myBufferBMP
Can you give a bit more detail on it, im thinking that one holds the bitmap data and one is the referance to it and SelectObject does the linking. And what is GetDC(0), does that get it a unique DC? Thanks for the tutorial! (If this comment was disrespectful, please report it.)
|
7/17/2006 10:25:28 PM: Junaid
Nice tutorial Tim 5 Globs From me..well i got a little problem too which i am unable to solve even after wasting my too much time...the problem is that i can't get this backbuffer into work when there is a bitmap in the background it just completely turn the bitmap black and when i tried vbSrcPaint to blit the background then the background problem got fixed and a new problem got generated and that problem was that it didnot clear out the old sprite data...someone help please i am a reallll beginner at vb,Thanks (If this comment was disrespectful, please report it.)
|
8/21/2006 8:48:54 PM: trouble_maker
I haven't read all the coments here so I don't know if anyone noticed a small bug in the code, it has to do with GetDC(0) <- you shouldn't use it like this! use GetDC(Form1.hdc) instead. In my case, I needed to constantly create and delete DC's and I noticed that the App memory kept growing until the program crashed. The rest of the tutorial is great and helped me a lot! Not to mention my App is 20-30% faster. (If this comment was disrespectful, please report it.)
|
8/25/2006 12:07:33 PM: trouble_maker
correction: instead of GetDC(0) use just Form.hdc not GetDC(Form.hdc) ai I mentioned before, sorry (If this comment was disrespectful, please report it.)
|
11/14/2006 11:17:50 PM: Kamaron Peterson
Thanks this is some awesome code, it really helped. 5/5. (If this comment was disrespectful, please report it.)
|
2/8/2007 11:13:46 AM: Nite Software Solutions
BitBlt is only one function in the entire GDI library. A simple look at www.allapi.net is really all you need to learn an API function. This doesn't deal with anything other than BitBlt. (If this comment was disrespectful, please report it.)
|
4/27/2007 8:28:31 AM: Angelo
i got black square? (If this comment was disrespectful, please report it.)
|
5/28/2007 4:11:13 AM: David
Cool code. You show how to load an image from a file into memory.
What about if the image is in an array? How can we convert that into a picture with a handle?
Thanks. David (If this comment was disrespectful, please report it.)
|
8/8/2007 12:08:40 AM: bigbigdog
thank you ,your tutor let me know more (If this comment was disrespectful, please report it.)
|
9/12/2007 10:31:09 PM: pietro ing. cecchi
very important tutorial...:) thanks a lot 5 stars (If this comment was disrespectful, please report it.)
|
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)
To post feedback, first please login.
|