Solved

Image Transparency

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

832 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