Solved

Image Transparency

Posted on 2003-11-22
3
288 Views
Last Modified: 2010-05-03
I have a 24 bit bitmap file (.bmp) with a white background. (RGB 255,255,255 or #FFFFFF) I have used lines of code that look like this:

Set myImage = FormName.Controls.Add("VB.image", "ImageName")
Set myImage.Picture = LoadPicture("C:\Mypic.bmp")

This is so the image is brought into the application dynamically, during run-time. Is there any way that I can make this image have a transparent background? By transparent, I mean so when it is placed upon another image, the white parts of myImage will actually show what is under it. I need this to make a game. Any help would be greatly appreciated. Thanks everybody!

~momonja
0
Comment
Question by:momonja
  • 2
3 Comments
 
LVL 5

Expert Comment

by:ennixo
ID: 9805752
you can do this from Device Context to Device Context with the TransparentBlt API

'Declaration
Private 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

'In your code
TransparentBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbWhite

'this will draw Picture1 on Picture2 with white (vbWhite) as transparent color
0
 

Author Comment

by:momonja
ID: 9807994
this doesn't do anything for me, I'm not quite sure why... I've got a Picture1 on my form, and a Picture2, Picture1 has the image.
0
 
LVL 5

Accepted Solution

by:
ennixo earned 120 total points
ID: 9808059
sorry i forgot to tell you that pictures scalemodes must be Pixel

Picture1.ScaleMode = vbPixel
Picture2.ScaleMode = vbPixel

or in the property editor
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

791 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