Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Image Transparency

Posted on 2003-11-22
3
Medium Priority
?
295 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 480 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

618 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