Real-Time Image Blending/Transparency (VB6)

Real-time transparency has become so commonplace in modern games and PC applications that it’s almost taken for granted.  However, the specific formula that performs this now-ubiquitous effect is worth understanding.

Transparency is simply a weighted average between the color values of two pixels.  As an example, consider the following two colors:

Pure red, or RGB(255, 0, 0)

Pure blue, or RGB(0, 0, 255)

At 50% transparency – or a pure blending between these two colors – we would simply add the individual color amounts together and divide by two.  This gives us a new color –

Purple, or RGB(127, 0, 127)

Not entirely surprising, eh?

The effect is certainly more impressive when applied pixel-by-pixel across an entire image, as the downloadable project demonstrates.

Squall and Rinoa meet a large flower (insert Garden joke of your choice :)
Squall and Rinoa meet a large flower (insert Garden joke of your choice :)

Similar Posts:


DISCLAIMER: These download files are regularly scanned to ensure they remain free from malicious content. Unfortunately, some virus scanners will flag these .zip files as suspicious simply because they contain source code and/or executable files. I have submitted my projects to a number of companies in an attempt to rectify these false-positives. Some have been cooperative. Others have not. If your virus scanner alerts you regarding these files, please allow the file to be submitted for further analysis (if your program allows for that). This should help ensure that any false-positive warnings gradually disappear for all users.

This site - and its many free downloads - are 100% funded by donations. Please consider a small contribution to fund server costs and to help me support my family. Even $1.00 helps. Thank you!

4 thoughts on “Real-Time Image Blending/Transparency (VB6)”

  1. your code is excelent… but i need ask these: how can i show 1 image transparency in UC(UserControl)?
    i’m sorry and thanks

  2. Hi Joaquim – I’m afraid I don’t fully understand your question. The DIB code above should work on any control that has an hDC property. You’ll have to tweak the functions themselves a bit (as they currently accept Picture Boxes, then extract the hDC from there), but there is no reason that you can’t use DIB sections to modify the pixel data returned from any hDC.

  3. Yes, can use the effect on a non-DC object. However, you’ll need to use the GetDC() API call to convert the object’s hWnd into a DC. Try this:

    Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long

    When you’re finished with the DC, use ReleaseDC to free up resources:

    Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As Long, ByVal hdc As Long) As Long

Comments are closed.