Solved

Image Transparency

Posted on 2003-11-22
3
285 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 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

18 Experts available now in Live!

Get 1:1 Help Now