Results 1 to 4 of 4

Thread: Transparent BitBlt?

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Transparent BitBlt?

    I found a tutorial on planet source code, and I understand a bit more about the API, however I am still stuck, as the tutorial didn't cover transparencies. Is there a way to use BitBlt on images with transparent backgrounds, or even have the images show up as transparent when an Alpha channel is used?

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    If you want an easier way, then I found that using vbSrcAnd as the flag will copy everything BUT white. Use white as the transparent colour and :

    BitBlt Me.hDC, 0, 0, 100, 100, Picture1.hDC, 0, 0, vbSrcAnd

    of course it does not work well if white is one of your colours for your picture.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  4. #4

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    I'm sorry I didn't mention this before, but the tutorial used double buffering to draw the background and the objects. No picturebox is used. Does this matter?

    This is the code that paints the background and objects

    VB Code:
    1. Private Sub cmdTest_Click()
    2.     Dim T1 As Long, T2 As Long
    3.     myBackBuffer = CreateCompatibleDC(GetDC(0))
    4.     myBufferBMP = CreateCompatibleBitmap(GetDC(0), 320, 256)
    5.     SelectObject myBackBuffer, myBufferBMP
    6.     BitBlt myBackBuffer, 0, 0, 320, 256, 0, 0, 0, vbWhiteness
    7.     mySprite = LoadGraphicDC(App.Path & "\sprite1.bmp")
    8.     cmdTest.Enabled = False
    9.     T2 = GetTickCount
    10.     Do
    11.         DoEvents
    12.         T1 = GetTickCount
    13.         If (T1 - T2) >= 15 Then
    14.             BitBlt myBackBuffer, SpriteX - 1, SpriteY - 1, 32, 32, 0, 0, 0, vbBlackness
    15.             BitBlt myBackBuffer, SpriteX, SpriteY, 32, 32, mySprite, 0, 0, vbSrcPaint
    16.             BitBlt Me.hdc, 0, 0, 320, 256, myBackBuffer, 0, 0, vbSrcCopy
    17.             SpriteX = SpriteX + 1
    18.             SpriteY = SpriteY + 1
    19.             T2 = GetTickCount
    20.         End If
    21.     Loop Until SpriteX = 320
    22. End Sub

    Where would I use vbSrcAnd in this case?

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