Page 1 of 2 12 LastLast
Results 1 to 40 of 42

Thread: Transparent BitBlt

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    23

    Transparent BitBlt

    Before you post that god damn link in my face again, let me tell you that I don't understand what the hell its all about. So refrain from posting that little link that has absolutely no help, and EXPLAIN IN LAMENS TERMS HOW TO REPLACE TRANSPARENT COLORS USING BITBLT. Im using magenta and i want to replace it with the background tile. its an image over an image.

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I have no clue how to do this. When you try making a mask, it doesnt work. Right?

    The reason is that the mask will only work if the white pixels in the mask are black pixels on the sprite. So that means that the transparent colour must be black in addition to having a mask. This stuck me for about half a year, it was very confusing.

    I hope you learned from my mistakes.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    23
    This is crazy. I need to know how to do transparencies. I KNOW its possible. I've seen it done. I just cant extract the subs from the source because its too complicated and webs throughout the entire project.

  4. #4
    denniswrenn
    Guest
    Here's a very simple example of how to do transparency. In the original picture, if the background is white, in the mask the background must be black, and all other stuff must be white...
    Attached Files Attached Files

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    23
    I downloaded this before but its NOT what i want
    do you people not understand?

    [edited by OEJ]


    sorry, but you people are trying to make this seem so hard for yourselves.
    Last edited by One Eyed Jack; Jul 2nd, 2001 at 02:49 AM.

  6. #6
    denniswrenn
    Guest
    what do you mean without the squareness around it? take the border off of the 3rd picture box, and you won't be able to tell it's square.

    There is no need for obscenities you ****ing ****, we were all just trying to help you. Maybe we would serve you better if we could understand your moronic interpretation of the english language.

    AND DON'T TYPE IN ALL CAPS, IT IS REALLY ANNOYING!

    First you say you want to replace transparent colors using BitBlt, then you say you need to know how to "do" transparencies, whatever the **** that means. Then you say you need the "squareness" removed from an image... Every time you post, you request something different, and expect us to cater to your every whim?

    Would you please type, and think slower so we can understand what you are trying to say?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    23
    Like this

    It sickens me how you people can't understand a simple task. That's why I get so angry!

  8. #8
    denniswrenn
    Guest
    If you would've just fooled around with my project, a little bit, you would have found it did just that.... enlarge the 3rd picture box and color the background blue.. run the program, and you get a red blob inside a blue Picture Box....

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    23
    No, im definitely not seein it.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    23
    Okay nevermind now I am.
    Problem: My graphics USE black in them- will that matter?
    Question: Can i make it change MAGENTA instead of black?


    And this isnt the method i had in mind.
    I know theres a way to take a direct image without making a black mask for it. Ive SEEN it done.

  11. #11
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88

    Angry

    No offense, but insulting people is not the way to get them to help you. You're d@mn lucky that people are responding to you at all anymore.

    You want an explaination? Fine, here, but you better start being more civil.

    If your mask has white in the "transparent" parts and your picture has black in the "transparent" parts:

    1. Bitblt the mask onto the image using the "vbSrcAnd" RasterOp. This will turn a section of your background totally black. These solid black pixels will be the ones to which the image will be painted.
    2. Bitblt the picture onto the image using the "vbSrcPaint" RasterOp. All non-black pixels will combined into the image... black pixels will stay black ;-)

    If your mask AND picture both have white in the "transparent Parts", you must change the RasterOps slightly:

    1. Bitblt the mask using "vbMergePaint". This will turn part of the background totally white.
    2. Bitblt the mask using "vbSrcAnd". This will paint the picture into the white area of the background.

    Getting angry with the people who are trying to help you is not an effective means of getting what you want. :-(

    As for using magenta as your "transparent" color, I would suggest that you create the mask based on that color, remove the transparent color, and then use one of the abovementioned methods.

    To create the mask/remove the color, use something like this:

    Dim x As Long, y As Long
    For y = 0 To nHeight
    For x = 0 To nWidth
    SetPixel maskDC, x, y, IIf(GetPixel(hSrcDC, x, y) = lTransColor, vbWhite, vbBlack)
    Next x
    Next y

    Where SetPixel() and GetPixel() are declared as

    Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

    -Hand out
    Last edited by The Hand; Jul 2nd, 2001 at 09:15 AM.
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  12. #12
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    yep..

    btw: there's also a createmask API where you can select any color and it will return the mask or something.. never used it, but exists for sure

  13. #13
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well I posted at the start, that's how you do it, you must use black. Although you can use srcInvert then MergePaint I THINK to use another colour.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  14. #14
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    Originally posted by Fox
    yep..

    btw: there's also a createmask API where you can select any color and it will return the mask or something.. never used it, but exists for sure
    Hmmm.... CreateMask API... Is that a Windows2000 thing maybe?

    I know there are differences between the GDI32 for Win98 and Win95, but "CreateMask" is a new one on me.

    What Lib is that in?
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  15. #15
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I would think it would have to be in GDI32...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  16. #16
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    Originally posted by Sastraxi
    I would think it would have to be in GDI32...
    That's not in my GDI32 lib (Win98)... checked it w/ PEInfo prog from "Win32 API Programming with Visual Basic" book. (attached)

    -Hand out
    Attached Files Attached Files
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  17. #17
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    Originally posted by Fox
    yep..

    btw: there's also a createmask API where you can select any color and it will return the mask or something.. never used it, but exists for sure
    Looks like the "CreateMask" method is in VB.NET... which exists only in beta form.

    Oh well... looks like I'm gonna have to stick to my old tricks.
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    23
    Well ive seen the stuff to this other matrix game, and its got images with just magenta backgrounds- nothing else. How do they do this? I still dont fully understand.

    Probably because progeix taught me BitBlt and he's only 14 years old :P

  19. #19
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well then try different combinations instead of AND and PAINT. Try PAINT and then AND. Try INVERT and then AND. Try INVERT and then PAINT. Try PAINT and then MERGEPAINT. Try INVERT and then MERGEPAINT...

    Just tell us what works for future refrence.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  20. #20
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    That is one darned useful proggie . (PEInfo)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  21. #21
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    I just re-discovered something I saw previously but totally forgot:

    There is a TransparentBlt function for Windows98/2000. Its contained in a DLL called "msimg32.dll". If you have this on your PC, you should be able to use the function. Included in this dll are also methods for AlphaBlending & Gradient Filling!!!!

    the TransparentBlt function is declared as:

    Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean

    If you want a good example, go to www.allapi.com and download their API guide. It also has an example for the "AlphaBlend" function.

    While this DLL supposedly only comes with Win98/2000, I have written small test programs and copied/installed that DLL to the test machine; it worked just fine under NT and 95 as well.

    -Hand out
    Last edited by The Hand; Jul 3rd, 2001 at 01:56 PM.
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  22. #22
    denniswrenn
    Guest
    It's not a good idea to use TransparentBlt(), there have been discussions about it before. It supposedly 'causes bad memory leaks

  23. #23
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It does, and it is only available (like you said) for Win98/2000. That's the reason that it is undocumented.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  24. #24
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    Originally posted by denniswrenn
    It supposedly 'causes bad memory leaks
    EEEEEEEEEEEEeeeeeeeeeeeeeeeek! <Runs screaming>

    Not that I didn't believe you, but I confirmed the memory leak. Just did the example prog that comes for TransparentBlt with the AllApi guide, and just called TransparentBlt every 100 milliseconds. Within 5 seconds my resources were critically low. I was just blting from one Picturebox hDC to another, so I know it has nothing to do with cleaning up handles/resources.

    That's no good. How about the AlphaBlend function? Any problems with that? I haven't used either one >>EVER<< but I did think about using AlphaBlend in my next project...

    Thanks!
    -Hand out
    Last edited by The Hand; Jul 3rd, 2001 at 02:35 PM.
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  25. #25
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    In about 2 years it will be okay to use. It's because Win95 doesn't support it. You can get around this with DDraw/D3D. But if you want Win95 users to miss out be my guest.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  26. #26
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    Originally posted by Sastraxi
    In about 2 years it will be okay to use. It's because Win95 doesn't support it. You can get around this with DDraw/D3D. But if you want Win95 users to miss out be my guest.
    They won't miss out if I distribute msimg32.dll with my apps... but I don't think I wanna include a DLL w/ a known memory leak

    -Hand out
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  27. #27
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    In lack of decent API's why don't you code them yourself?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  28. #28
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    Originally posted by kedaman
    In lack of decent API's why don't you code them yourself?
    I don't need the TransparentBlt function. That was One-Eyed-Jack who wanted it. I'm fine with using RasterOps, BitBlts, and masks.

    As for the AlphaBlend function, I know how to do it on a pixelwise basis, but that takes REALLY REALLY long for large pics.

    -Hand out
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  29. #29
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    well transparency is one of the slowest possible 2D things... Even on my Voodoo5 5500 it slows down to critical framerate in 3D games if there's many transparent polygons on screen

    Well if you can use HAL (even windowed) it's fast enough, and rotations of course too... as long as you aren't in ASM that's the best you can do.

  30. #30
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Make sure to use D3D7 not D3D8, because your gfx card might not support dx8.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  31. #31
    denniswrenn
    Guest
    Originally posted by Fox

    Well if you can use HAL

    What the HAL is that? ()

  32. #32
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    what's HAL?

    As for the AlphaBlend function, I know how to do it on a pixelwise basis, but that takes REALLY REALLY long for large pics.
    You could get reasonable framerate if you alphablend in small scale, most games that have 2d alphablending don't alphablend more than 5% of the screen at a time.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  33. #33
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    With Directdraw, you can get some DMA with an array as a pointer... Not really a pointer but it kind of is. You can change the colour bits pretty fast although it's slow compared to the Win98/2k alphablend function.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  34. #34
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    Well, what I really need is a way to multiply an array of integers by the same number quickly.

    I'm not talking about a "For i = 1 to Ubound: Next i" type thing... I'm talking about a CopyMemory type thing.

    If I could multiply every number in an array by something with one or two (Or even 10) API steps and avoid looping thru the pixels, I could easily code my own alphablend function.

    Oh well.
    -Hand out
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  35. #35
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by The Hand
    Well, what I really need is a way to multiply an array of integers by the same number quickly.

    I'm not talking about a "For i = 1 to Ubound: Next i" type thing... I'm talking about a CopyMemory type thing.

    If I could multiply every number in an array by something with one or two (Or even 10) API steps and avoid looping thru the pixels, I could easily code my own alphablend function.

    Oh well.
    -Hand out
    You do know what CopyMemory does do you? It loops from the first to the last byte and assigns it to another range. It's no kind of "magic" behind CopyMemory or Bitblt as lot's of people out here think. It's correct that it is easy to do, but you won't accomplish speedy alpha blend without C++ or even preferable ASM.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  36. #36
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88
    Originally posted by kedaman
    It's no kind of "magic" behind CopyMemory or Bitblt as lot's of people out here think.
    There's no such thing as magic, just an incredible desire to do the impossible which makes it realization...

    Yeah, I know how CopyMemory and Bitblt work, however they are standard API routines which were written in C++ or ASM... and therefore available to all machines. I don't want to have to write my own DLL because that's just one more thing to distribute with my code... I could just as easily distribute that red-headed stepchild msimg32.dll

    I was hoping there was a standard API call to multiply everything in an array by a scalar... maybe something in Kernel32 or User32, but if not... guess I'll just have to forget about it. Being a standard API call, it would already be on all my users' machines and would be (hopefully) already optimized for speed.

    I should have taken the opportunity to learn ASM years ago, but I'm too old now to learn... old dog/new tricks, ya know

    Later,
    -Hand out
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

  37. #37
    denniswrenn
    Guest
    Maybe you could create a static library in C++ for the function... Not sure if they'll work in VB though.

  38. #38
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by The Hand

    I was hoping there was a standard API call to multiply everything in an array by a scalar... maybe something in Kernel32 or User32, but if not... guess I'll just have to forget about it. Being a standard API call, it would already be on all my users' machines and would be (hopefully) already optimized for speed.
    Standard api calls for paranoid vb-programmers. I don't think so I'm extreemly paranoid programmer myself so I know what you are feeling but also know what you should do to it by now.
    "One more thing to distribute with my executable" i've heard this so many times i'm sick of it. If your files are part of your application, not any public api's, then they won't be in the way of the user, besides c++ dll's aren't entered into registry unlike activeX ones.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  39. #39
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    What you could do is like Sentience does, it automatically generates the masks when you run the "RunMeFirstToInstall.exe" or whatever

    Anyway, if you're still interested in alpha blend... look in my signature <cough cough>
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  40. #40
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    masks? that automatically doubles the amount of memory allocated for sprites + doubles the amount of time by performing 2 blit's And hehe, in case you use jotaf's alphablend, it automatically quadrouples both memory and time j/k i haven't checked it out, but with most certainity it is
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Page 1 of 2 12 LastLast

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