原文链接: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 > Then
Call GdipGetPropertyItemSize(hImage, PropertyTagFrameDelay, pSize)
ReDim pItem_(pSize - )
ReDim GifFramesDelay(fCount - )
Call RtlZeroMemory(ByVal VarPtr(pItem_()), pSize)
Call GdipGetPropertyItem(hImage, PropertyTagFrameDelay, pSize, ByVal VarPtr(pItem_()))
'这里我把最后一个参数的类型(PropertyItem)改成了Any,直接读内存方便些
For i = To pSize - Step
GifFramesDelay(j) = pItem_(i)
j = j +
Next
For i = To fCount -
Call GdipImageSelectActiveFrame(hImage, Guid, i)
Call GdipDrawImage(Graphics, hImage, , )
Call delay_(GifFramesDelay(i) * )
'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