原文链接: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 LongPrivate Sub Command1_Click()Dim hImage As LongDim Guid As ClsidDim dCount As LongDim fCount As LongDim pItem_() As ByteDim pSize As LongDim pDelay() As LongDim bmpCLSID As ClsidCall 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 ThenCall 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 4GifFramesDelay(j) = pItem_(i)j = j + 1NextFor i = 0 To fCount - 1Call 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&)NextEnd IfCall GdipDisposeImage(hImage) End SubPrivate Sub Form_Load()InitGDIPlusCall GdipCreateFromHDC(Form1.hdc, Graphics) End SubPrivate Sub Form_Unload(Cancel As Integer)Call GdipDeleteGraphics(Graphics)TerminateGDIPlus End SubPrivate Sub delay_(ByVal d As Long)Dim n As Longn = GetTickCount()Do Until n + d < GetTickCount()DoEventsLoop End Sub