Results 1 to 13 of 13

Thread: BitBlt transparency

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    115
    How do I blit something making one color (background) transparent?
    Vuen

  2. #2
    Guest
    See This topic. I explained, in detail how to do this.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    115

    Wink

    Ok, I understand the rest but why does SrcPaint not paint the blackness? And is there a way to do this without a mask, like just paint all except the color RGB(0, 255, 255)? Oh and SrcCopy combines the 2 colors (source and destination pixels), it doesnt paint not whiteness.

    http://msdn.microsoft.com/library/wc...r/uif_ac_6.htm :
    SRCPAINT
    Combines the colors of the source and destination rectangles by using the Boolean OR operator.

    ???

    Oh well. Now I have to make a mask version of all my pics.

    [Edited by Vuen on 07-31-2000 at 03:39 PM]
    Vuen

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    115
    Ok but um if I don't have any 255-255-255 colors in my bitmap I dont need to use the mask right?

    Hold on I'm trying it...
    Vuen

  5. #5
    Guest
    You would still need to use a Mask regardless of which colours you have. If you don't use a Mask, your picture will either appear darker or watered down.

  6. #6
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Just copy your background picture to a DC in memory (memDC)

    Consider the transparent picture, loop thru x and y and if a dot is found <> transp. colour, put it into memDC with the same x and y

    Now your picture is transparent on the chosen background in memory, just put it back with BitBlt() on the Form.

    Using memory DC is very very FAST!
    Consider also scrolling effects...


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    115
    Are you sure a memory DC is fast because I don't know if i'm doing something wrong or what but it's SLOW AS HELL AAAAAAAAAAHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!! I use CreateCompatibleDC and CreateCompatibleBitmap and SelectObject the hBitmap into the hDC and then use SetPixelV on the DC. That is slow as hell and it's so frustrating to not be able to pallete a graphic at runtime because of the slowness, so I have to do a GIANT waiting loading time to pallete all the pics like 8 times each for each different pallete I want and well 2500 50x50 pics 8 times each where it does about 5 pics per second is one hell of a load time. I tried experimenting with GetDIBits and stuff but could never get it to work. If you could PLEASE PLEASE TEACHME!!! to use this I would be very greatful..
    Vuen

  8. #8
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Unhappy

    It depends on how you want to use the memDC. I used it for creating transparency on 64x64x16bit pictures and this went faster than using picture boxes.
    I also use this to keep painted backgrounds in memory. So if I print something on the background, normally I can't re-print on the same position unless I use the Cls method. But Cls gives us the flickering phenomenon.
    So I keep the background image in memory and when I want to print on the same position, I perform a BitBlt around the printed text with the corresponding background area. Then I can print the new line.
    When I use this method to perform scrolling numbers (with large fontsize) the flicker seems to dissappear and happens much faster.

  9. #9
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    You don't need to draw maskpictures.

    You can just let your program calculate them and put it into a DC
    Sanity is a full time job

    Puh das war harter Stoff!

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    115
    um guys, THAT DIDNT TELL ME ANYTHING!!!!!!!!!!!!!! You just said "let the program calculate them." What the hell is that! Tell me HOW you got to transparently blit your pictures Mad Compie! Did you use SetPixel?
    Vuen

  11. #11
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Talking

    I see you're hungry, Vuen!
    Yes indeed I used SetPixel(), but now I found some really interesting algoritm to tile images (like texture backgrounds) and a solid TransBlt function! This TransBlt function works more faster than mine, so I'll give you the link were you can find this zipped file:
    http://www.devx.com/free/codelib/view.asp?id=352405
    The routines are in a BAS called CUSTOMBLT.BAS.

    I hope that your fingernails remain intact by now...

  12. #12
    Guest
    The best way to make a picture transparent is this

    Public Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long

    Public Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long

    if you set nBkMode=1 then the picture is transparent

  13. #13
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Hmmm, I don't really think so my friend.

    Code:
    If (GetDeviceCaps(hDestDC, CAPS1) And C1_TRANSPARENT) Then
          '
          ' Some NT machines support this *super* simple method!
          ' Save original settings, Blt, restore settings.
          '
          OrigMode = SetBkMode(hDestDC, NEWTRANSPARENT)
          OrigColor = SetBkColor(hDestDC, TransColor)
          Call BitBlt(hDestDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, vbSrcCopy)
          Call SetBkColor(hDestDC, OrigColor)
          Call SetBkMode(hDestDC, OrigMode)      
       Else
          '...
    End If

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