(50 pts) Make Image Transparent

I'm creating an ActiveX control that will display pictures and make them transparent by specifying the transparent color.  This is similar to .GIF's where you specify the transparent color and it's thereafter transparent.

Is there way to set the transparent color of an image so that the image is transparent?  For example, if I put a BITMAP (.BMP) image with a black background into a PictureBox control... is there a way to set the transparent color of the picturebox to 0 so that the black background now is transparent and it is thereafter possible to see objects that are under the PictureBox in the areas that were black?

The way I'd like to use this is in an ActiveX control, set the BackStyle property of the UserControl of the ActiveX to Transparent, then set the transparent color of the UserControl to 0 so that the picture is the only thing that is visible.  Or perhaps put a PictureBox control on the UserControl of the ActiveX... set the UserControl to Transparent and them make the transparent color of the PictureBox 0 so it's transparent.

Maybe I'm barking up the wrong tree as far as how to go about this, these are just ideas of how to make a picture transparent.  Can anyone help me with this one?

Thanks,

HATCHET
LVL 3
HATCHETAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HATCHETAuthor Commented:
Edited text of question.
0
crazymanCommented:
I dont think you can make bmp's transapent.....
0
HATCHETAuthor Commented:
crazyman,

I'm looking to make the transparency on the PictureBox or UserControl, not the actual picture... thereby making the transparency color of the control transparent for it's Picture no mater what picture it contains... .GIF, .BMP, .JPG, etc.

I know it can be done because I have an ActiveX control that does it... I'd like to encourperate that into something I'm doing with out having to use his control as a dependency.

I also know that there is a little known or used transparency bit in Bitmap files.  I don't know much more about it, or transparency in general so that's why I'm asking this question.

HATCHET
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

crazymanCommented:
I have a project that may be some use its too much to paste ,have you got an email i can send it to you.
0
crazymanCommented:
I dont know if this helps but maybe you could modify it
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=3664
0
HATCHETAuthor Commented:
I'll check it out.  Thanks.

HATCHET
0
HATCHETAuthor Commented:
crazyman,

I did get that sample of yours to work to do what I need done.  I substituted the form for the UserControl of the ActiveX and it works perfectly.  However, my question of how to make a PictureBox picture transparent by making a color transparent hasn't been answered.  I'm gunna mess around with this sample and see if I can get the principles used in it to work with a single control.

If someone can answer how to do the aforementioned, I'll give you and that person points.  If no one else has any ideas about this, I'll accept your answer because I'm getting done what needs to be done for now.

Thanks again for the sample.

HATCHET
0
tommy_boyCommented:
'Selecting a Colour from a Picture -  And Masking that Colour
'you need to put a 2 command buttons and a picture box/image (one for preview) on a form for this code to work, as well as an image list for example
'the purpose is basically to MASK a selected colour from the image with the background colour

'Modify it as you will, it is just to give you the idea.  I use it in conjunction with a file selection dialog (to select what I want mask)


Option Explicit
Private mv_ColourSelected As Long

Private Sub cmd_Close_Click()
  Unload Me
End Sub

Private Sub cmd_preview_Click()
  '..Preview the Mask/Unmask
  On Error GoTo err_mask
  Picture1.Picture = ImageList1.Overlay(1, 1)
  frmName.txtBackColour(frmName.P_Image_Type) = mv_ColourSelected
  Exit Sub
err_mask:
  Err = 0
End Sub


Private Sub Form_Load()
 '** This Form Selects the Tranparent Colour for the Selected Image
 Dim imgX As ListImage
  frmMaskSelect.ScaleMode = vbPixels
  '..Load bitmap
  On Error GoTo mask_image_load_err
  Select Case frmName.P_Image_Type
  Case 0
    '..Add the Image to the Image List
    Set imgX = ImageList1.ListImages. _
    Add(, , LoadPicture(frmName.txtMainImage))
    '..If there is a current mask colour then display it
    If frmName.txtBackColour(0) <> "" Then
      '..make the current back colour is numeric
      If IsNumeric(frmName.txtBackColour(0)) Then
        mv_ColourSelected = frmName.txtBackColour(0)
        '..force the Image List to use the mask colour
        ImageList1.UseMaskColor = True
        '..Set the Mask Colour of the List Image
        ImageList1.MaskColor = mv_ColourSelected
      Else
        '..if the mask colour is not numeric - reset it back on the options screen
        frm_Options.txtBackColour(0) = ""
      End If
    End If
  Case 1
    '..Add the Image to the Image List
    Set imgX = ImageList1.ListImages. _
    Add(, , LoadPicture(frmName.txtSubImage))
  '..If there is a current mask colour then display it
    If frm_Options.txtBackColour(1) <> "" Then
      '..make the current back colour is numeric
      If IsNumeric(frmName.txtBackColour(1)) Then
        mv_ColourSelected = frmName.txtBackColour(1)
        '..force the Image List to use the mask colour
        ImageList1.UseMaskColor = True
        '..Set the Mask Colour of the List Image
        ImageList1.MaskColor = mv_ColourSelected
      Else
        '..if the mask colour is not numeric - reset it back on the options screen
        frm_Options.txtBackColour(1) = ""
      End If
    End If
  End Select
  '..overlay (display) the masked/unmasked picture - which ever is applicable
  Picture1.Picture = ImageList1.Overlay(1, 1)
  Exit Sub
mask_image_load_err:
  Err = 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Set frmMaskSelect = Nothing
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  '..select the desired colour from the pic
  On Error GoTo err_mousedown
  mv_ColourSelected = Picture1.Point(x, y)
  ImageList1.UseMaskColor = True
  ImageList1.MaskColor = mv_ColourSelected
err_mousedown:
  Err = 0
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tommy_boyCommented:
And this should have been 100 points
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.