Solved

Having problems drawing a transparent bitmap...

Posted on 2002-06-07
13
266 Views
Last Modified: 2013-11-20
I can't figure out what's wrong with this code:

void VIMaskedBitmap::TransparentStretchBlt( CDC* pDestDC,
                                                      MOSINT32 nDestX,
                                                      MOSINT32 nDestY,
                                                      MOSINT32 nDestWidth,
                                                      MOSINT32 nDestHeight,
                                                      CDC* pSrcDC,
                                                      MOSINT32 nSrcX,
                                                      MOSINT32 nSrcY,
                                                      MOSINT32 nSrcWidth,
                                                      MOSINT32 nSrcHeight,
                                                      COLORREF cr )
{
     CSize szSrc( nSrcWidth, nSrcHeight );
     CSize szDest( nDestWidth, nDestHeight );

    CPoint ptSrc( nSrcX, nSrcY);
    CPoint ptDest( nDestX, nDestY);
   
     CDC dcAnd;
    CDC dcXor;

    dcAnd.CreateCompatibleDC( pDestDC );
    dcXor.CreateCompatibleDC( pDestDC );

     CBitmap bitmapAnd;
     CBitmap bitmapXor;
     bitmapAnd.CreateBitmap( szSrc.cx, szSrc.cy, 1, 1, NULL );
     bitmapXor.CreateCompatibleBitmap( pSrcDC, nSrcWidth, nSrcHeight );

    // Create an AND mask
    CBitmap* pOldBitmapAnd = dcAnd.SelectObject( &bitmapAnd );

    COLORREF crOld = pSrcDC->SetBkColor( cr );
    dcAnd.BitBlt( 0, 0, szSrc.cx, szSrc.cy, pSrcDC, ptSrc.x, ptSrc.y, SRCCOPY );
     pSrcDC->SetBkColor( crOld );

     // Create an XOR mask
    CBitmap* pOldBitmapXor = dcXor.SelectObject( &bitmapXor );

    dcXor.BitBlt( 0, 0, szSrc.cx, szSrc.cy, pSrcDC, ptSrc.x, ptSrc.y, SRCCOPY );

    dcXor.BitBlt( 0, 0, szSrc.cx, szSrc.cy, &dcAnd, NULL, NULL, 0x220326 );

     // Generate the final image by applying the AND and XOR masks
    pDestDC->StretchBlt( ptDest.x, ptDest.y, szDest.cx, szDest.cy,
                               &dcAnd,
                               ptSrc.x, ptSrc.y, szSrc.cx, szSrc.cy,
                               SRCAND );

    pDestDC->StretchBlt( ptDest.x, ptDest.y, szDest.cx, szDest.cy,
                               &dcXor,
                               ptSrc.x, ptSrc.y, szSrc.cx, szSrc.cy,
                               SRCINVERT );

    dcXor.SelectObject( pOldBitmapXor );
    dcAnd.SelectObject( pOldBitmapAnd );
}
0
Comment
Question by:dwinkler
  • 6
  • 4
  • 3
13 Comments
 
LVL 8

Expert Comment

by:fl0yd
ID: 7062578
Not very descriptive -- what kind of problem? Does your code raise an error? Is your result not as you'd expect it to be? If so, how does it appear?
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 7062729
See http://www.codeguru.com/bitmap/CISBitmap.shtml ("Transparent Bitmap - True Mask Method "), maybe this is of some help...
0
 
LVL 86

Expert Comment

by:jkr
ID: 7062864
Hum, thanx, but why a "C"? If it doesn't work for you, don't accept it, and if it does, it was certainly worth more than a "C"...
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:dwinkler
ID: 7062893
Well I figured it out the problem before you answered so since you were probably the most usefull then I gave you the points... but not because you found the problem with the given code.  It was a lazy answer.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7062901
@ jkr:
I'd be pissed, too -- guess there will be no more helping dwinkler from me. A personal ban-list would be cool. The type of question should have given us enough hints, though. Just throwing code at people to go through and tell the 'author' what's wrong -- he wasn't even giving a description about what went wrong. Too bad, it's too late now :(

@ dwinkler:
What exactly is wrong with the link provided by jkr?
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7062907
@ dwinkler:
IT WAS A LAZY QUESTION IN THE FIRST PLACE111111111
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7062916
@ dwinkler:
IT WAS A LAZY QUESTION IN THE FIRST PLACE111111111
0
 
LVL 86

Expert Comment

by:jkr
ID: 7062960
>> personal ban-list would be cool

Don't worry, I do have one :o)
But, it takes more to get on it than just grading a "C"...
0
 

Author Comment

by:dwinkler
ID: 7063081
Not looking to make enemies so calm down a bit.  The reality is that jkr got the points regardless.  That is a thanks for trying...  I have nothing else to say... fl0yd, next time you see a question from me just ignore it, if you feel that I've done something this bad to you...
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7063230
You're just being selfish in the most explicit way. Your 'I paid for what I got'-mentality is manifestation enough. Just to enlighten you a bit: There could be someone stumbling across your question in the future. Based on your grade he/she might buy the answer or not -- a 'C' isn't really something I'd go for. To make it short: Give it as much credit as you think the information priveded is worth. A comment like "it was a lazy answer" pretty much disqualifies you from becoming a talented coder anyway.
0
 

Author Comment

by:dwinkler
ID: 7063251
jkr sorry for the grade but no way to change it now...  fl0yd, Not sure what you're talking about but get off my back and get a life...
0
 
LVL 86

Expert Comment

by:jkr
ID: 7063266
Well, all this has a good side also - we found a serious EEBug :o)

I never received ANY notifications for dwinklers comments after my comment was accepted, but I did receive notifs for fl0yds comments... Report posted :o)

(dwinker: Just imagine you'd have to ask a followup, and I'd never have responded because of the lack of a notification - would have made me look pretty bad :o)
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7063292
Glad I could help out :) As for the lack of notification from dwinkler I'd call it a feature rather than a bug ;)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to determine file rename from EventLog ? 2 55
sumDigits challenge 9 170
has22 challenge 11 104
changeXy challenge 13 88
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question