Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
XML RSS Feed
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleOverlay an image on another using a simple mask
Keywordsoverlay, mask, picture, foreground, background
CategoriesGraphics
 
  1. Use PaintPicture to copy the background into the result PictureBox.
  2. Copy the mask onto the result picture using vbMergePaint opcode to erase pixels corresponding to black parts of the mask.
  3. Invert the mask with the vbNotSrcCopy opcode.
  4. Copy the reversed mask onto the foreground picture using the vbMergePaint opcode. That erases parts of the foreground image that correspond to the black parts of the reversed mask.
  5. Copy the reverse masked foreground image onto the masked background using the vbSrcAnd opcode.
 
Private Sub cmdGo_Click()
    ' Make a temporary copy of the foreground picture.
    picMaskedForeground.PaintPicture picForeground.Picture, _
        0, 0
    picMaskedForeground.Picture = picMaskedForeground.Image

    ' Copy the background to the result PictureBox.
    picResult.PaintPicture picBackground.Picture, 0, 0
    picResult.Picture = picResult.Image

    ' Copy the mask onto the result picture using
    ' the vbMergePaint opcode to erase pixels
    ' corresponding to black parts of the mask.
    picResult.PaintPicture picMask.Picture, _
        0, 0, , , , , , , vbMergePaint
    picResult.Picture = picResult.Image

    ' Make a reversed mask. Copy the mask onto it
    ' using the vbNotSrcCopy opcode.
    picReverseMask.PaintPicture picMask.Picture, _
        0, 0, , , , , , , vbNotSrcCopy
    picReverseMask.Picture = picReverseMask.Image

    ' Copy the reversed mask onto the foreground
    ' picture using the vbMergePaint opcode. That
    ' erases parts of the foreground image that
    ' correspond to the black parts of the reversed
    ' mask.
    picMaskedForeground.PaintPicture _
        picReverseMask.Picture, _
        0, 0, , , , , , , vbMergePaint
    picMaskedForeground.Picture = picMaskedForeground.Image

    ' Now we have a masked background that is white
    ' where we want the foreground image to go, and
    ' a reverse masked foreground image that is white
    ' where we want the background to show.

    ' Copy the reverse masked foreground image onto
    ' the masked background using the vbSrcAnd opcode.
    picResult.PaintPicture picMaskedForeground.Picture, _
        0, 0, , , , , , , vbSrcAnd
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated