Results 1 to 20 of 20

Thread: Make colors in pictures transparent using BitBlt or DirectX

  1. #1

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    Make colors in pictures transparent using BitBlt or DirectX

    I want to select a color to be transparent in a picture. I want to do this using BitBlt or DirectX not using Mask Color. Any help.

    Anyone know a good site to help me learn DirectX. I am a beginner.
    THE TIME/WEATHER IS
    Don't know how to use APIs or have problem with them,
    Download API-Guide & API-Viewer from http://www.allapi.net

  2. #2
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    How's your math?

    Are you any good at advanced math? boolean logic and the like?

    It should be possible with BITBLT because all the mask is doing is the hard part of the boolean logic equasions for you.

    Beets me tho' the furthest I got was A level stats many years ago
    ?
    'What's this bit for anyway?
    For Jono

  3. #3
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Re: How's your math?

    Originally posted by Matt_T_hat
    In case it is of any interest to anyone I've been learning VB since the summer. I am now considered the class expert as my questions usually bring in other departments or at least heads of departments before answers are found. College tutors kinda fear me I think.
    I had that with a Java class. I answered the questions. The tutor got paid...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    lol, problem here too.

    Anyways, to stick to the topic, Bitblt requires you also to have a mask picture. See more here:
    http://vbden.tripod.com/articles/invmask.htm
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562
    Code:
          BitBlt picDip.hDC, 0, 0, picDip.Width, picDip.Height, picMask(0).hDC, 0, 0, vbSrcAnd
         BitBlt picDip.hDC, 0, 0, picDip.Width, picDip.Height, picBlack.hDC, 0, 0, vbSrcPaint
         BB.Cls
         BitBlt BB.hDC, 0, 0, BB.Width, BB.Height, picMask(1).hDC, 0, 0, vbSrcAnd
         BitBlt BB.hDC, 0, 0, BB.Width, BB.Height, picDip.hDC, 0, 0, vbSrcPaint
    
         BitBlt Surface.hDC, 0, 0, Surface.Width, Surface.Height, BB.hDC, 0, 0, vbSrcCopy
    How about making the yellow color in my picture invisible.

    Sastraxi, Can you please explain a bit. I am only familiar with SRCCOPY. I understand the white color is not being painted on picDip & BB and in the last paint the color is being painted only on the black surface of BB.

    Thank you.
    Attached Files Attached Files
    • File Type: zip p1.zip (617 Bytes, 69 views)
    THE TIME/WEATHER IS
    Don't know how to use APIs or have problem with them,
    Download API-Guide & API-Viewer from http://www.allapi.net

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    That last technique is used for inverse masking - colour dipping. It makes, say, a green silhouette of the mask on your picture. To do masking, all it takes is two calls:
    VB Code:
    1. BB.Cls
    2. Bitblt BB.hDC, 0, 0, picMask.ScaleWidth, picMask.ScaleHeight, picMask.hDC, 0, 0, vbSrcAnd
    3. Bitblt BB.hDC, 0, 0, picMask.ScaleWidth, picMask.ScaleHeight, Surface.hDC, 0, 0, vbSrcPaint
    Sorry if I've caused any confusion there.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562
    Duh! that change didn't give any output. What about making the blue color in the picture I attached invisible. Anyway I attached my project. Can you please check it out.
    Thank you.
    Attached Files Attached Files
    THE TIME/WEATHER IS
    Don't know how to use APIs or have problem with them,
    Download API-Guide & API-Viewer from http://www.allapi.net

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Make the BG black. That will solve all your problems. It must be pure black (0,0,0).
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Whoops! I think you can change the first to MergePaint, and the second to AND, but keeping the dest. any colour. That's what I said in my tutorial, 'cause someone told me that.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562
    OK that got the white surface in the picture invisible. But what if I want to make any color invisible. Like the sprite control attached (written by Fox). It uses Mask color property, but I want to use BitBlt or DirectX to make it perform faster.
    Attached Files Attached Files
    THE TIME/WEATHER IS
    Don't know how to use APIs or have problem with them,
    Download API-Guide & API-Viewer from http://www.allapi.net

  11. #11
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    When I get home, I'll try to make it work. Somehow I don't think my BitBlt tutorial is as complete as it should be, maybe I'll start revising it.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I think he knows that, I directed him to my tutorial a bit earlier and I covered that topic.

    http://vbden.tripod.com/articles/invmask.htm
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Here's a full example on using MergePaint, download the MergePaint.zip that I attached in that thread.

    http://www.vbforums.com/showthread.p...hreadid=125073
    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
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    I've struggled a bit with using getbitmapbits and pixelsV to create a mask in memory on the fly but it's too damn slow for full screen selections. Any words on this you can offer?

  15. #15
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yes- create them beforehand. I know it's really annoying, but it would be best to create them in the same way as you do your other 2D surfaces. You could also use OCX packages that could do this for you in C++ code. Search around for one. The only other alternative is DirectDraw memory access. The masks could be generated that way.
    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
    Banned Motxopro's Avatar
    Join Date
    Dec 2001
    Posts
    57
    yeah he's right

  17. #17

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    Got it

    I got exactly what I wanted at vbexplorer. In this project you don't need a Mask picture.
    Too bad it only works with 4-bit & 8-bit pictures.
    It uses an API not listed in WinAPI32.txt.
    THE TIME/WEATHER IS
    Don't know how to use APIs or have problem with them,
    Download API-Guide & API-Viewer from http://www.allapi.net

  18. #18

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    ... and one more :)

    This project has a code found in vbexplorer. It creates the mask picture needed to have transparent background
    THE TIME/WEATHER IS
    Don't know how to use APIs or have problem with them,
    Download API-Guide & API-Viewer from http://www.allapi.net

  19. #19
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    NOOOOOO

    TransparentBlt leaks memory every time you use it. Don't use it. Do yourself and your end users' favours and remove it from your app. Use a white bg with the mergepaint/and combo, its worth getting rid of memory leaks you'll cause. Ooh, gimme a sec.
    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

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562
    WOW I never knew that. Thanks for the warning. I guess I just use the mask technique or the Sprite Control.
    THE TIME/WEATHER IS
    Don't know how to use APIs or have problem with them,
    Download API-Guide & API-Viewer from http://www.allapi.net

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