PDA

Click to See Complete Forum and Search --> : BitBlt API function


farah
Jun 1st, 2000, 04:54 AM
How can I use BitBlt API Function? can anyone help here.
I want a transparent picture.

Public 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

Fox
Jun 1st, 2000, 05:15 AM
Theres a really easy example on my website (http://foxmccloud.tsx.org).

Jun 1st, 2000, 05:21 AM
Use MS Paint to make a black box (100x100) with a small green circle in the middle. Then load the picture in a PictureBox on the Form.

Put this code in 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

Make sure all Controls have their SclaeMode set to Pixel

Put this code in a Commandbutton


Private Sub Command1_Click()

' Copy all colours but Black. The SRCAND is what doesn't
' Copy the black. If you use SRCPAINT, it will not copy
' the white.
status = BitBlt(Form1.hDC, 0, 0, 100, 100, Pciture1.hDC, 0, 0, SRCAND)

End Sub



This should work.

Jun 1st, 2000, 05:24 AM
I forgot to add this. These ae different Constants that you can use instead of SRCAND.


Public Const SRCAND = &H8800C6 ' (DWORD) dest = source AND dest
Public Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Public Const SRCERASE = &H440328 ' (DWORD) dest = source AND (NOT dest )
Public Const SRCINVERT = &H660046 ' (DWORD) dest = source XOR dest
Public Const SRCPAINT = &HEE0086 ' (DWORD) dest = source OR dest

Jun 2nd, 2000, 04:40 AM
you dont need to add the constants to the module.
the other day fox told me about vb's built in bitblt constants...

vbSrcCopy
vbSrcPaint


etc...

:D
thank you fox.

Fox
Jun 2nd, 2000, 05:15 AM
np :)

btw: To make these black/white masks you need to blit bitmaps transparent you can use my mask generator. I think it's coming with the engine demo on my site...

Jun 2nd, 2000, 09:02 AM
how and why do you make/use masks?

Jun 2nd, 2000, 08:22 PM
You need to use Masks because when you copy the Sprite (picture) you do not copy Black, thus, the background colours will leak through. In order to make it solid, you need to add the back colour to it. That is why you copy down the Mask first (to get the black) then you copy the original Picture to add the rest of the colours.

Jun 3rd, 2000, 12:51 AM
huh?

what do you mean?

why dont you copy black?

cant you just directly copy the picture to the form's dc, or the other pic box's dc?

wait, I think I understand.
say you have a pic. its a jet with a silver border with the inside black. you dont copy the inside, instead, you
put this mask onto picbox or whatever, then you do the orig. picture..
ok I understand... but why do you do this? why cant you just copy the black down?

Fox
Jun 3rd, 2000, 04:13 AM
Because of the ROP you use. vbSrcPaint for example subtracts the pixels from the destination, that means you only get the black part.
Then you add the picture with vbSrcAdd coz Black+AnyColor -> AnyColor, White+AnyColor stays the same, that's why the original pictures have a white background)

Hope you understand what I mean ;)

Jun 3rd, 2000, 06:34 AM
If your next question is "What can't we just use SrcCopy and get the whole thing?" then I think you cannot do that in games because it will copy what ever is in that area. for example, if you have half of the picture covered by a Commandbutton, it will copy the Commandbutton as well.

Fox
Jun 3rd, 2000, 07:06 AM
Megatron, that only hapens when you set AutoRedraw to false as fas as I remember ;)

Jun 3rd, 2000, 07:59 AM
fox is right...
that has happened to me before, when i was just learning bitblt(i now have a full 4 days experience. :) )

I even have a vauge idea on how to detect collisions... but shooting things is my problem...
how do I shoot a laser or something?

from the middle of the ship?
I tried this


bitblt picture1.hdc, picture2.top, (picture1.scalewidth - picture2.left) + (picture2.scalewidth / 2), etc.

so it would start in the middle of the ship, right above it...
but it didnt work....
any suggestions?

Jun 3rd, 2000, 08:15 AM
If you want to know about shooting lasers, you can go to http://www.planet-source-code.com and get a program called LaserDraw, it's a really neat program, that draws something using "lasers"

Jun 3rd, 2000, 08:37 AM
thanks megatron

Jun 3rd, 2000, 11:37 PM
thanks alot megatron, but that wasnt what I was looking for, I was talking about, like shooting a missle or bullet, or laser, or something out of the ship.
can anyone help me with that?

Jun 4th, 2000, 03:03 AM
Use BitBlt to draw the bullet (animate it until it goes off the screen). While it's shooting, keep checking if the X and Y positions match the positions of the object you're trying to shoot. If it does, than the object is destoryed.