Solved

Having problems drawing a transparent bitmap...

Posted on 2002-06-07
13
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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