Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleOverlay one image on another with a transparent color by using PSet
DescriptionThis example shows how to overlay one image on another with a transparent color by using PSet in Visual Basic 6.
KeywordsPSet, overlay, transparent
CategoriesGraphics
 
This program simply loops through the pixels in the images. For each image in top-to-bottom order, the program looks for a color other than the one defined as transparent. When it finds such a color, it stops looking at the images and sets the output pixel's color using PSet.
 
Private Sub cmdCombine_Click()
Dim max_input As Integer
Dim transparent As Long
Dim wid As Single
Dim hgt As Single
Dim X As Single
Dim Y As Single
Dim i As Integer
Dim clr As Long

    cmdCombine.Enabled = False
    MousePointer = vbHourglass
    DoEvents

    max_input = picInput.ubound
    For i = 0 To max_input
        picInput(i).AutoRedraw = True
        picInput(i).ScaleMode = vbPixels
    Next i

    picResult.Width = picInput(0).Width
    picResult.Height = picInput(0).Height
    picResult.ScaleMode = vbPixels

    transparent = picTransparent.BackColor
    wid = picInput(0).ScaleWidth
    hgt = picInput(0).ScaleHeight
    For Y = 0 To hgt
        For X = 0 To wid
            For i = max_input To 0 Step -1
                clr = picInput(i).Point(X, Y)
                If clr <> transparent Then Exit For
            Next i
            picResult.PSet (X, Y), clr
        Next X
        DoEvents
    Next Y
    picResult.Picture = picResult.Image

    cmdCombine.Enabled = True
    MousePointer = vbDefault

    Beep
End Sub
 
Note that there are faster ways to access color values in V 6 and VB .NET, and that there are faster methods for merging images if you have an overlay mask. Note also that VB .NET provides tools for setting a transparent color for an image so this problem is trivial in VB .NET.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated