VB6之GIF分解

原文链接:http://hi.baidu.com/coo_boi/item/1264a64172fe8dec1f19bc08

 

还是找了个C++的翻译下,原文链接:http://www.360doc.com/content/05/1122/15/1894_34348.shtml

GDI+的函数声明 我就不放上了,网上有个做好的GDI+公共模块。

Private Declare Sub RtlZeroMemory Lib "kernel32" (dest As Any, ByVal numBytes As Long)
Private Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private GifFramesDelay() As Long
Private Graphics As Long
        
Private Sub Command1_Click()
    Dim hImage As Long
    Dim Guid As Clsid
    Dim dCount As Long
    Dim fCount As Long
    Dim pItem_() As Byte
    Dim pSize As Long
    Dim pDelay() As Long
    Dim bmpCLSID As Clsid
            
    Call GdipLoadImageFromFile(StrPtr("d:\1.gif"), hImage)
    Guid = GetImageEncoderClsid(GIF)
    'bmpCLSID = GetImageEncoderClsid(BMP)
    Call GdipImageGetFrameDimensionsCount(hImage, dCount)
    Call GdipImageGetFrameDimensionsList(hImage, Guid, dCount)
    Call GdipImageGetFrameCount(hImage, Guid, fCount)
    If fCount > 1 Then
        Call GdipGetPropertyItemSize(hImage, PropertyTagFrameDelay, pSize)
        ReDim pItem_(pSize - 1)
        ReDim GifFramesDelay(fCount - 1)
        Call RtlZeroMemory(ByVal VarPtr(pItem_(0)), pSize)
        Call GdipGetPropertyItem(hImage, PropertyTagFrameDelay, pSize, ByVal VarPtr(pItem_(0)))
        '这里我把最后一个参数的类型(PropertyItem)改成了Any,直接读内存方便些
        For i = 16 To pSize - 1 Step 4
            GifFramesDelay(j) = pItem_(i)
            j = j + 1
        Next
        For i = 0 To fCount - 1
            Call GdipImageSelectActiveFrame(hImage, Guid, i)
            Call GdipDrawImage(Graphics, hImage, 0, 0)
            Call delay_(GifFramesDelay(i) * 10)
            'Call GdipSaveImageToFile(hImage, StrPtr("d:\" & i & ".bmp"), bmpCLSID, ByVal 0&)
        Next
    End If
    Call GdipDisposeImage(hImage)
End Sub
        
Private Sub Form_Load()
    InitGDIPlus
    Call GdipCreateFromHDC(Form1.hdc, Graphics)
End Sub
        
Private Sub Form_Unload(Cancel As Integer)
    Call GdipDeleteGraphics(Graphics)
    TerminateGDIPlus
End Sub
    
Private Sub delay_(ByVal d As Long)
    Dim n As Long
    n = GetTickCount()
    Do Until n + d < GetTickCount()
        DoEvents
    Loop
End Sub

 

posted @ 2014-12-04 13:47  lichmama  阅读(658)  评论(0编辑  收藏  举报