Link to home
Start Free TrialLog in
Avatar of wau
wau

asked on

MaskBlt (how to draw masked image?)

::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.
Avatar of wau
wau

ASKER

Edited text of question
Avatar of wau

ASKER

Edited text of question
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
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.
Avatar of wau

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of AlFa
AlFa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you all! I got same problem and your answers help me a lot.
But a little bit funny is that I don't even do two first steps...
just "::BitBlt(main_DC, x, y, cx, cy, sub_DC, x, y, SRCAND);"

and that's worked! The image in sub_DC is transparent in main_DC.
I don't really understand, can somebody explain to me?