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
LVL 19
BrianGEFF719Asked:
Who is Participating?
 
List244Commented:
BitBlt Canvas.hDC, 0, 0, Wmask.ScaleWidth, Wmask.ScaleHeight, Wmask.hDC, 0, 0, vbSrcAnd
BitBlt Canvas.hDC, 0, 0, Wmask.ScaleWidth, Wmask.ScaleHeight, Wpawn.hDC, 0, 0, vbSrcPaint

This will work if your mask is black/white (White where transparent
black where opaque) Then your other image should be black where
transparent. Your mask should always be white/black though. Not
colorful.
0
 
BrianGEFF719Author Commented:
Quick late followup, I've seen masks be pink, whats that about?

-Brian
0
 
List244Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.