Link to home
Start Free TrialLog in
Avatar of BrianGEFF719
BrianGEFF719Flag for United States of America

asked on

Masking Problem

I am using BitBlt to mask an image:

lngRet = BitBlt(canvas.hDC, RealX, RealY, wMask.ScaleWidth, wMask.ScaleHeight, wMask.hDC, 0, 0, vbMergePaint)
lngRet = BitBlt(canvas.hDC, RealX, RealY, wPawn.ScaleWidth, wPawn.ScaleHeight, wPawn.hDC, 0, 0, vbSrcAnd)


where wPawn is the image I want and wMask is the mask of wPawn. However, I am having a hard time, i've tried different colors as the mask and had weird results. I've tried the mask as Pink with the Good Area as black and had the best results. But I still see the pink area!


Help.
Brian
ASKER CERTIFIED SOLUTION
Avatar of List244
List244

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
Avatar of BrianGEFF719

ASKER

Quick late followup, I've seen masks be pink, whats that about?

-Brian
Avatar of List244
List244

Many times you will see images with a pink background.
In the games they will appear transparent. However, as
far as I am aware, this can not be done using BitBlt. These
are not truly masks, but the images. The thing you miss out
on here, is the fact that the color pink becomes a color you
can not use in your picture. Using BitBlt you can use ANY
color, because of the mask, which tells where to be transparent.

Here is how the pink would work.

For X = 0 to PictureWidth
 For Y = 0 to PictureHeight
  If Not (ColorOfPixel = Pink) Then
   SetPixel DrawTo.DC, X,Y, GetPixel(PictureDC,X,Y)
  End If
 Next Y
Next X

A way you could do this is:

Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean

This function is similar to BitBlt, except now rather than the raster-operation
code, it wants to know what color to ignore.

ANY color can be made transparent, pink is used as it is easy to get along
without.