Solved

Having problems drawing a transparent bitmap...

Posted on 2002-06-07
13
262 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 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

20 Experts available now in Live!

Get 1:1 Help Now