[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

(50 pts) Make Image Transparent

Posted on 1999-12-16
9
Medium Priority
?
221 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:HATCHET
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Author Comment

by:HATCHET
ID: 2287079
Edited text of question.
0
 
LVL 13

Expert Comment

by:crazyman
ID: 2287080
I dont think you can make bmp's transapent.....
0
 
LVL 3

Author Comment

by:HATCHET
ID: 2287111
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 13

Expert Comment

by:crazyman
ID: 2287174
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
 
LVL 13

Expert Comment

by:crazyman
ID: 2287194
I dont know if this helps but maybe you could modify it
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=3664
0
 
LVL 3

Author Comment

by:HATCHET
ID: 2287214
I'll check it out.  Thanks.

HATCHET
0
 
LVL 3

Author Comment

by:HATCHET
ID: 2287832
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
 
LVL 1

Accepted Solution

by:
tommy_boy earned 100 total points
ID: 2288241
'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
 
LVL 1

Expert Comment

by:tommy_boy
ID: 2288243
And this should have been 100 points
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

612 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