Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Having problems drawing a transparent bitmap...

Posted on 2002-06-07
13
Medium Priority
?
274 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 800 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

886 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