Masking Problem

Posted on 2004-10-26
Last Modified: 2010-05-02
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!

Question by:BrianGEFF719
    LVL 8

    Accepted Solution

    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
    LVL 19

    Author Comment

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

    LVL 8

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    846 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

    8 Experts available now in Live!

    Get 1:1 Help Now