Solved

Image Transparency

Posted on 2003-11-22
3
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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