Results 1 to 17 of 17

Thread: BitBlt API function

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 1999
    Location
    San Diego, Ca , USA
    Posts
    44
    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

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Theres a really easy example on my website.

  3. #3
    Guest
    • 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

      Code:
      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

      Code:
      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.



  4. #4
    Guest
    I forgot to add this. These ae different Constants that you can use instead of SRCAND.

    Code:
    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

  5. #5
    Guest
    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...


    thank you fox.

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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...

  7. #7
    Guest
    how and why do you make/use masks?

  8. #8
    Guest
    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.

  9. #9
    Guest
    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?

  10. #10
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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

  11. #11
    Guest
    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.

  12. #12
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Megatron, that only hapens when you set AutoRedraw to false as fas as I remember

  13. #13
    Guest
    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?

  14. #14
    Guest
    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"

  15. #15
    Guest
    thanks megatron

  16. #16
    Guest
    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?

  17. #17
    Guest
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width