Solved

MaskBlt (how to draw masked image?)

Posted on 1998-10-16
6
2,319 Views
Last Modified: 2013-11-20
::MaskBlt ( myHDC , 0 ,0 ,width ,height ,myhMemDC ,x ,y ,mymask ,0 ,0 ,raster_operation_code );
myHDC is a HDC of a window
myhMemDC is a HDC with a selected RGB bitmap
my mask is a HBITMAP of a monochrome bitmap.
What do I have to put in raster op. code to draw only in the part where my mask is white?
I tried with all methods listed in BitBlt but nothing.
And I tried with MAKEROP4 macro, but I dont understand what arguments to pass.
Help me peopple please.
0
Comment
Question by:wau
6 Comments
 

Author Comment

by:wau
ID: 1323469
Edited text of question
0
 

Author Comment

by:wau
ID: 1323470
Edited text of question
0
 

Expert Comment

by:bobbym
ID: 1323471
The idea is simple but you have to have an inverted mask too.
First combine the image and the mask using AND operation.
Then combine the background image and the  inverted mask again using AND. In this way you have the image and the clipped background. Then the only thing left to do is to draw them in the DC using OR and everything is OK. If you do not finish this by Monday i will send you some source :)

Hope that helped
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 6

Expert Comment

by:snoegler
ID: 1323472
I think bobbym is right. The mask needs to consist of RGB(255,255,255) where the original
pixel should be left, and RGB(0,0,0) where you want to replace it by your own bitmap data.

BTW: mymask is one parameter too much ... What do you mean by it?

::BitBlt(myHDC,0,0,width,height,myhMemDC_MaskBitmap,x,y,0,0,SRCAND);
::BitBlt(myHDC,0,0,width,height,myhMemDC_RealBitmap,x,y,0,0,SRCPAINT);

Where myhMemDC_MaskBitmap has the mask bitmap selected,
and myhMemDC_RealBitmap has the 'real' bitmap selected. Of course both DC's may be the
same.
0
 

Author Comment

by:wau
ID: 1323473
I done it.
It's working.

BitBlt( image_DC,0,0,width,height,mask_DC,x,y,SRCAND );
BitBlt( wnd_DC,0,0,width,height,mask_invert_DC,0,0,SRCAND );
BitBlt( wnd_DC,0,0,width,height,image_DC,0,0,SRCPAINT );

Thanks very much.
0
 
LVL 2

Accepted Solution

by:
AlFa earned 50 total points
ID: 1323474
I use this I think you can transform it.
it draw a bitmap with a colour defined transparent


void DrawTransparent(CDC * pDC, CBitmap *pThisBmp, int x, int y, int W, int H,      int nWidth, int nHeight, COLORREF crColour, CPalette* Palette)
{
      CBitmap & ThisBmp = *pThisBmp;
      COLORREF crOldBack = pDC->SetBkColor(RGB(255,255,255));
      COLORREF crOldText = pDC->SetTextColor(RGB(0,0,0));
      CDC dcImage, dcTrans;
      // Create two memory dcs for the image and the mask
      dcImage.CreateCompatibleDC(pDC);
      dcTrans.CreateCompatibleDC(pDC);
      // Select the image into the appropriate dc
      CBitmap* pOldBitmapImage = (CBitmap*)dcImage.SelectObject(pThisBmp);
      if (Palette)
      {
            dcImage.SelectPalette(Palette, TRUE);
      }

      // Create the mask bitmap
      CBitmap bitmapTrans;
      bitmapTrans.CreateBitmap(nWidth, nHeight, 1, 1, NULL);
      // Select the mask bitmap into the appropriate dc
      CBitmap* pOldBitmapTrans = dcTrans.SelectObject(&bitmapTrans);
      // Build mask based on transparent colour
      dcImage.SetBkColor(crColour);
      dcTrans.BitBlt(0, 0, nWidth, nHeight, &dcImage, 0, 0, SRCCOPY);
      // Do the work - True Mask method - cool if not actual display
      pDC->SetStretchBltMode( COLORONCOLOR);
      pDC->StretchBlt( x, y, W, H, &dcImage, 0, 0, nWidth, nHeight, SRCINVERT );
      pDC->StretchBlt( x, y, W, H, &dcTrans, 0, 0, nWidth, nHeight, SRCAND );
      pDC->StretchBlt( x, y, W, H, &dcImage, 0, 0, nWidth, nHeight, SRCINVERT );
      // Restore settings
      dcImage.SelectObject(pOldBitmapImage);
      dcTrans.SelectObject(pOldBitmapTrans);      
      pDC->SetBkColor(crOldBack);
      pDC->SetTextColor(crOldText);
}

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
How to create frequencies of a variable from SAS dataset? 10 121
Process filename extension 3 172
WinWaitActive parameters 12 31
sumNumber challenge 16 110
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

920 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

13 Experts available now in Live!

Get 1:1 Help Now