Import .gif image in vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vaniKanabathy
    New Member
    • Mar 2008
    • 52

    Import .gif image in vb6

    Hi , i had problem in import .gif image. I had call the image using

    Image32.Picture = LoadPicture(App .Path & "\a.gif")

    the image appear in my form but it not animated as it was. Please help me to
    import gif images in vb6?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Please find a related discussion here .

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      Also check this link for another discussion.

      Comment

      • vaniKanabathy
        New Member
        • Mar 2008
        • 52

        #4
        Hi...thanks 4 the reply. I had try using other coding to import .gif image , the problems is the images are flickering to much. The flickering very can be seen strongly when i import many images using image control. The codes are as below

        -------the module
        [code=vb]
        Option Explicit
        Public RepeatTimes As Long 'This one calculates,
        ' but don't use in this sample. If You need, You
        ' can add simple checking at Timer1_Timer Procedure
        Public TotalFrames As Long

        Public Function LoadGif(sFile As String, aImg As Variant) As Boolean
        LoadGif = False
        If Dir$(sFile) = "" Or sFile = "" Then
        MsgBox "File " & sFile & " not found", vbCritical
        Exit Function
        End If
        On Error GoTo ErrHandler
        Dim fNum As Integer
        Dim imgHeader As String, fileHeader As String
        Dim buf$, picbuf$
        Dim imgCount As Integer
        Dim i&, j&, xOff&, yOff&, TimeWait&
        Dim GifEnd As String
        GifEnd = Chr(0) & Chr(33) & Chr(249)
        For i = 1 To aImg.Count - 1
        Unload aImg(i)
        Next i
        fNum = FreeFile
        Open sFile For Binary Access Read As fNum
        buf = String(LOF(fNum ), Chr(0))
        Get #fNum, , buf 'Get GIF File into buffer
        Close fNum

        i = 1
        imgCount = 0
        j = InStr(1, buf, GifEnd) + 1
        fileHeader = Left(buf, j)
        If Left$(fileHeade r, 3) <> "GIF" Then
        MsgBox "This file is not a *.gif file", vbCritical
        Exit Function
        End If
        LoadGif = True
        i = j + 2
        If Len(fileHeader) >= 127 Then
        RepeatTimes& = Asc(Mid(fileHea der, 126, 1)) + (Asc(Mid(fileHe ader, 127, 1)) * 256&)
        Else
        RepeatTimes = 0
        End If

        Do ' Split GIF Files at separate pictures
        ' and load them into Image Array
        imgCount = imgCount + 1
        j = InStr(i, buf, GifEnd) + 3
        If j > Len(GifEnd) Then
        fNum = FreeFile
        Open "temp.gif" For Binary As fNum
        picbuf = String(Len(file Header) + j - i, Chr(0))
        picbuf = fileHeader & Mid(buf, i - 1, j - i)
        Put #fNum, 1, picbuf
        imgHeader = Left(Mid(buf, i - 1, j - i), 16)
        Close fNum
        TimeWait = ((Asc(Mid(imgHe ader, 4, 1))) + (Asc(Mid(imgHea der, 5, 1)) * 256&)) * 10&
        If imgCount > 1 Then
        xOff = Asc(Mid(imgHead er, 9, 1)) + (Asc(Mid(imgHea der, 10, 1)) * 256&)
        yOff = Asc(Mid(imgHead er, 11, 1)) + (Asc(Mid(imgHea der, 12, 1)) * 256&)
        Load aImg(imgCount - 1)
        aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPer PixelX)
        aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPer PixelY)
        End If
        ' Use .Tag Property to save TimeWait interval for separate Image
        aImg(imgCount - 1).Tag = TimeWait
        aImg(imgCount - 1).Picture = LoadPicture("te mp.gif")
        Kill ("temp.gif")
        i = j
        End If
        DoEvents
        Loop Until j = 3
        ' If there are one more Image - Load it
        If i < Len(buf) Then
        fNum = FreeFile
        Open "temp.gif" For Binary As fNum
        picbuf = String(Len(file Header) + Len(buf) - i, Chr(0))
        picbuf = fileHeader & Mid(buf, i - 1, Len(buf) - i)
        Put #fNum, 1, picbuf
        imgHeader = Left(Mid(buf, i - 1, Len(buf) - i), 16)
        Close fNum
        TimeWait = ((Asc(Mid(imgHe ader, 4, 1))) + (Asc(Mid(imgHea der, 5, 1)) * 256)) * 10
        If imgCount > 1 Then
        xOff = Asc(Mid(imgHead er, 9, 1)) + (Asc(Mid(imgHea der, 10, 1)) * 256)
        yOff = Asc(Mid(imgHead er, 11, 1)) + (Asc(Mid(imgHea der, 12, 1)) * 256)
        Load aImg(imgCount - 1)
        aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPer PixelX)
        aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPer PixelY)
        End If
        aImg(imgCount - 1).Tag = TimeWait
        aImg(imgCount - 1).Picture = LoadPicture("te mp.gif")
        Kill ("temp.gif")
        End If
        TotalFrames = aImg.Count - 1
        Exit Function
        ErrHandler:
        MsgBox "Error No. " & Err.Number & " when reading file", vbCritical
        LoadGif = False
        On Error GoTo 0
        End Function[/code]

        ---- vb form

        [code=vb]Dim FrameCount As Long

        Private Sub Command1_Click( )
        Timer1.Enabled = False
        If LoadGif(Text1, Image1) Then
        FrameCount = 0
        Timer1.Interval = CLng(Image1(0). Tag)
        Timer1.Enabled = True
        End If
        End Sub

        Private Sub Command2_Click( )
        Timer1.Enabled = False
        End Sub

        Private Sub Command3_Click( )
        Timer1.Enabled = True
        End Sub

        Private Sub Form_Load()

        Text1.Text = App.Path & IIf(Right(App.P ath, 1) = "\", "", "\") & "e.gif"
        Timer1.Enabled = False
        End Sub

        Private Sub Timer1_Timer()
        If FrameCount < TotalFrames Then
        Image1(FrameCou nt).Visible = False
        FrameCount = FrameCount + 1
        Image1(FrameCou nt).Visible = True
        Timer1.Interval = CLng(Image1(Fra meCount).Tag)
        Else
        FrameCount = 0
        For i = 1 To Image1.Count - 1
        Image1(i).Visib le = False
        Next i
        Image1(FrameCou nt).Visible = True
        Timer1.Interval = CLng(Image1(Fra meCount).Tag)
        End If
        End Sub[/code]

        Please help to solve the problem. Thanks in advance.
        Last edited by debasisdas; Apr 3 '08, 10:25 AM. Reason: added code=vb tags

        Comment

        Working...