How can I emulate a BitBlt function in VB.Net?

solokin1

New member
Joined
Feb 27, 2003
Messages
4
hi,

I just recently switched over to VB.Net in the midst of my coding a Diablo II-clone, and I have noticed that there is no BitBlt function, so I tried using the GDI DrawImage method.

This works fine if I am loading a bitmap from disk into a picturebox, but I cannot then copy a selected rectangle from that picturebox into another picturebox!

It says that there is no image in the previous picture box, and so it cant copy the selected portion! Is there something I;m doing wrong or should i use directdraw9 or what?

Help requested before I physically burn my copy of VB.NET :)

SOloKing
 
Anything you draw on a picturebox is essentially temporary. It isnt stored anywhere, its just displayed on the screen. This is important for performance purposes. If you want to do something like you are trying to do, you need to create an offscreen bitmap. This is easy enough using the Bitmap class. You can get a graphics object from that bitmap using Graphics.FromImage() and draw on it.

Once you have drawn on it you are free to assign it to a picturebox if you like, to display it. You do this with the pictureboxs Image property. If you want to use DrawImage to draw a portion of your offscreen bitmap to another Graphics object, you can also do so. Several overloads for Graphics.Drawimage allow you to specify a source rectangle to blt from.
 
There is also another problem with the Drawimage function as far as games go: it is slower that bitblt. It appears to be just as slow as the VB6 .paintpicture method. You can still use bitblt in VB.net the same way as you do in vb6. The only difference is that you need the GetDC() windows API function to get the handle to the device context for a control, since it is not provided as a property.
 
Back
Top