Solved

Having problems drawing a transparent bitmap...

Posted on 2002-06-07
13
263 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rewrite URL With Encoded Characters 6 75
Looking for a specific application/software 2 104
maxBlock challenge 30 111
Smart Camera scanning and reading information 3 99
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now