Does anybody know how to create transparant bitmap on another bitmap that has variation background ? i mean by using masm32 (coding) we can emulate photoshop working to copy a slice of picture from one bitmap after we used lasso tools for example to be combined to another bitmap that has scenary picture for example so the result as if the combined picture scenary and sliced picture were coming from one picture.

i have tried with the steps :

create first bitmap (white background) contains picture to be combined to third bitmap
create second bitmap contains the same black picture for masking (white background)
create third bitmap contains scenary picture for example (colourful background)

1. By using BitBlt function, create blackhole picture to third bitmap from first bitmap using SRCAND (ROP)

2. By using BitBlt function , create bitmap contains picture from first bitmap with black background using
combination of raster operation DSTINVERT,SRCCOPY and SRCAND.

3. By using BitBlt function, create last bitmap combination of 1 and 2 using SRCPAINT

But the problem is only working for white background, i try to apply with my scenary background the resulted bitmap is not correct as photoshop done

does anybody have the answer ? because this is the basic of animation with so many backgrounds
Posted on 2004-03-18 05:39:04 by newbies

invoke SelectObject,memDC,PicMask
invoke BitBlt,hdc,0,0,32,32,memDC,0,0,SRCAND
invoke SelectObject,memDC,Pic
invoke BitBlt,hdc,0,0,32,32,memDC,0,0,SRCPAINT

works fine for me unless i have a picture and a mask to that picture
Mask = same picture but only black and white.
the mask picture must be white in the areas you want transparent
Posted on 2004-03-18 14:31:28 by bj1500
i have tried with my steps but just working for one iteration i mean after the picture successfully be combined with the colourful background smoothly, i want to move the picture to the next position by increasing x value for example but the blackhole of picture from previous steps is still exist so the part of background eaten by picture for combination cannot be recovered. I tried to save the rectangle of background that has the same size with bitmap contained picture for first iteration before making combination and used that part for next iteration but the result is looking ugly. How to get the part of backgound missed because of and operation by picture to be recovered if we want to move the picture to the another position ?
Posted on 2004-03-18 21:02:50 by newbies
Hi :)

There are probably a lot of solutions to this problem, this is the easiest one I can think of right now: To begin with, you must have a bitmap with the sprite you want to move, and another one with the full background. Also, make sure to have an extra bitmap and DC for backbuffering. Then, just BitBlt the background to your backbuffer, then your sprite. Then BitBlt the backbuffer into the window DC.

Another (better) way to do it: You must have a bitmap with the sprite, and a "backup" bitma. BitBlt the part of the background that will be overwritten into the backup bitmap. Then BitBlt the sprite into the background. When you move the sprite, first BitBlt the backup into the background first (to restore the original background).

BTW, you might want to use region objects instead of mask bitmaps, they work more like Photoshop's "lasso". Take a loot at this page:
Posted on 2004-03-19 11:56:33 by QvasiModo
Hi Newbies,

I struggled with the same problem a while ago and solved it with a relative simple solution. The trick is to use inverted sprite and mask! Just load your BMP of the sprite in Windows paint, choose invert and save it. And for the mask -> the pixels you want to visualize must be black, the ones you do not wanna see must be white color. Then use this code to bitblit on the DC:

invoke SelectObject,hMemDCX,hMask
invoke BitBlt,hMemDC,PosBMPx,PosBMPy,rect.right,rect.bottom,hMemDCX,0,0,SRCAND ;set the mask
invoke BitBlt,hMemDC,PosBMPx,PosBMPy,rect.right,rect.bottom,hMemDCX,0,0,DSTINVERT ;first inversion
invoke SelectObject,hMemDCX,hBitmap
invoke BitBlt,hMemDC,PosBMPx,PosBMPy,rect.right,rect.bottom,hMemDCX,0,0,SRCAND ;set the inverted sprite
invoke BitBlt,hMemDC,PosBMPx,PosBMPy,rect.right,rect.bottom,hMemDCX,0,0,DSTINVERT ;invert to normal color

The first SRCAND function will put on the inverted mask making a 'black hole' in the background where your sprite 'll come. Next the DSTINVERT function will invert the colors: the black hole becomes a white hole. But also the surounding colors are now inverted.
Now we'll put on the sprite with a second SCRAND function (make sure the sprite-bmp is inverted colors!). As a result of this we now have an inverted sprite on an inverted background. Thats why we have to do a second invertion with a second DSTINVERT function. it 'll invert the inverted bmp to its normal colors and also the surounding colors of the background. Voila, we have a sprite sitting on a background with various colors!
(The code above actually bitblits onto a backbuffer that gets transferred to the HDC, but that has no actual importance for now.)

The picture below illustrates the trick: it is a snapshot from the title-screen of my latest cardgame-project called Manillen. The cards are moving around above a background with moving lines and a scroller dancing a sine-wave. This picture is actually a thumbnail from my website concerning the game. If you wish to view a larger picture just visit and follow the link 'screenshots'

Hope this may help you.... ;)

Friendly greetings,

Lovesong (King of Diamonds).
Posted on 2004-03-26 17:17:24 by lovesong