GIFs lose transparency in ActiveX control

I have an activex control that allows the user to dynamically add image boxes to the control.  The pictures look great at first, but after they are saved to the propertybags and then reloaded, the gifs somehow lose their transparency.  Their background becomes a solid color.  Does anybody know how to stop this from happening.  The following code shows how I am saving and loading from the propertybags:


readproperties event:    
     
        Image.Picture = propbag.ReadProperty("Image")

writeproperties event:

        Call propbag.WriteProperty("Image", Image.Picture)
LVL 1
AllpaxAsked:
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.

Erick37Commented:
The problem is this:

Once you save the file, it is converted to a Windows bitmap and is no longer a GIF file.  That means the transparent property is lost.

Does the user select the GIF file, or is it a set file that you specify in code?
0
rajaloysiousCommented:
Give this a try..

You need to use UseMaskColor property in the ImageList Control
====Set UseMaskColor property and set it to true. This will allow Visual Basic to make the background colour of the icons transparent.

http://www.glyfx.com/guide_vb6.html

You have to put the images in a ImageList control and load the image boxes from there.
You must think of using controls other than imagebox, like a picture box to do this... but this is well possible

Cheers
0
AllpaxAuthor Commented:
The user selects the gifs while using the activex control.  The images that are static, and have a specific property related to them are fine.  It's only the dynamically loaded images into dynamically loaded image boxes that have the problem
0
Ultimate Tool Kit for Technology Solution Provider

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 now.

AllpaxAuthor Commented:
Can the imagelist control display all pictures to a user.  If so how?  Do I need to use something else to show the user the pictures?
0
AllpaxAuthor Commented:
The user dynamically adds images to the form.  I was originally using windows common dialog to show the file dialog box.  The user would select a picture from the file dialog.  If I use an imagelist I can no longer use the file dialog box.  Does anyone have a suggestion?
0
Erick37Commented:
Is it feasable in your application to only save the path to the original file and reload the original GIF file in ReadProperties event?
0
AllpaxAuthor Commented:
No, because once the activex control is set up by the user, it will be installed on other systems. Therefore the path will no longer ne good.
0
Erick37Commented:
Hi Allpax

I have been trying to reproduce the problem you described, but the transparency does seem to be retained using this code in my test usercontrol.  The transparent areas of the GIFs show the backcolor of the UserControl.

Option Explicit

Private m_pic As StdPicture

Public Property Get Pic() As StdPicture
    Set Pic = m_pic
End Property

Public Property Set Pic(NewPic As StdPicture)
    Set m_pic = NewPic
    Set Image1.Picture = m_pic
    PropertyChanged "Pic"
End Property

Private Sub UserControl_Initialize()
    'random backcolor
    Randomize
    UserControl.BackColor = RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Debug.Print "ReadProperties", Now
    Set m_pic = PropBag.ReadProperty("Pic", Nothing)
    Set Image1.Picture = m_pic
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Debug.Print "WriteProperties", Now
    PropBag.WriteProperty "Pic", m_pic, Nothing
End Sub
0
AllpaxAuthor Commented:
I'm sorry I should have been more specific.  The reason your code works is that you have a specific property related to the picture property.  My problem is that I might have to load 100 different image boxes dynamically, so I can't really have a defined property related to each of them.  If you try to save the image.picture to the propertybag you get the problem.
0
Erick37Commented:
Well I modified it to dynamically add image controls with pictures, and I still do not see the problem.  

Option Explicit

Private m_pic As Picture
Private NumPix As Long

Private Sub UserControl_Initialize()
    'random backcolor
    Randomize
    UserControl.BackColor = RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Debug.Print "ReadProperties", Now
    Dim pic As StdPicture
    Dim i As Long
   
    NumPix = PropBag.ReadProperty("NumPix", 0)
    If (NumPix > 0) Then
        For i = 1 To NumPix
            Set pic = PropBag.ReadProperty("Pic" & CStr(i), Nothing)
            Call Add(pic)
        Next
    End If
End Sub

Private Sub UserControl_Terminate()
    Dim ndx As Long
    If Image1.UBound = 0 Then Exit Sub
    'unload all the dynamic image controls
    For ndx = Image1.UBound To 1 Step -1
        Unload Image1(ndx)
    Next
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Debug.Print "WriteProperties", Now
    Dim i As Long
    NumPix = Image1.UBound
    If (NumPix > 0) Then
        For i = 1 To NumPix
            PropBag.WriteProperty "Pic" & CStr(i), Image1(i).Picture, Nothing
        Next
    End If
    PropBag.WriteProperty "NumPix", NumPix, 0
End Sub

Public Property Set NewPic(NewPicture As StdPicture)
    Set m_pic = NewPicture
   Call Add(m_pic)
   PropertyChanged "NewPic"
End Property

Public Property Get NewPic() As StdPicture
    Set NewPic = m_pic
End Property

Public Sub Add(NewPicture As StdPicture)
   'm_ic.Add NewPicture
   Dim ndx As Long
   ndx = Image1.UBound + 1
   Load Image1(ndx)
   With Image1(ndx)
   Set .Picture = NewPicture
   .Top = Int(Rnd * (UserControl.ScaleHeight / 1.5))
   .Left = Int(Rnd * (UserControl.ScaleWidth / 1.5))
   .Visible = True
   End With
End Sub
0
AllpaxAuthor Commented:
I used the same code you have and did the following

I enabled edit at design time.  
In the click event of the user control I added code to add picture.  

           Dim x As StdPicture
           Set x = LoadPicture("c:\crap.gif")
           Set NewPic = x

When I minimize the form, then maximize it I lose the transparency.
0
Erick37Commented:
Hi Allpax

Well I was able to see the problem by using the LoadPicture call in the UserControl_Click event in Edit mode.  I do believe that it is related to how LoadPicture translates/saves the picture.

I was able to load transparent GIFs by using the AsyncRead method of the usercontrol and it seems to retain the transparency through the WriteProperties/ReadProperties cycle.  Give it a try and see if it works out for you.

Private Sub UserControl_Click()
   
    'Trigger a "download" of the picture
    AsyncRead "c:\globe1.gif", vbAsyncTypePicture, "NewPicture", vbAsyncReadSynchronousDownload
   
End Sub

Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
   
    'This event is fired when the picture is downloaded
    If AsyncProp.PropertyName = "NewPicture" Then
        Set NewPic = AsyncProp.Value
    End If
   
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
AllpaxAuthor Commented:
Erik37

     Thanks for your help.  I just went ahead and added an imagelist to the usercontrol and added the images to that.  It seems to work fine with that.
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.