|
|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 lss001 于 2023-11-8 08:09 编辑
Private Declare Function GdipImageGetFrameCount Lib "gdiplus" (ByVal image As Long, _
dimensionID As Guid, Count As Long) As GpStatus
Private Declare Function GdipImageSelectActiveFrame Lib "gdiplus" (ByVal image As Long, _
dimensionID As Guid, ByVal frameIndex As Long) As GpStatus
Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf _
As GDIPlusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus
Private Declare Function GdipSaveImageToFile Lib "gdiplus" (ByVal image As Long, _
ByVal FileName As Long, guidEncoder As Guid, encoderParams As Any) As GpStatus
Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal FileName As String, image As Long) As GpStatus
Private Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As GpStatus
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal image As Long) As GpStatus
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hdc As Long, Graphics As Long) As GpStatus
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal Graphics As Long) As GpStatus
Private Declare Function CLSIDFromString Lib "ole32" (ByVal Str As Long, id As Guid) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Type Guid
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type GDIPlusStartupInput
GdiPlusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Enum GpStatus ' aka Status
OK = 0
GenericError = 1
InvalidParameter = 2
OutOfMemory = 3
ObjectBusy = 4
InsufficientBuffer = 5
NotImplemented = 6
Win32Error = 7
WrongState = 8
Aborted = 9
FileNotFound = 10
ValueOverflow = 11
AccessDenied = 12
UnknownImageFormat = 13
FontFamilyNotFound = 14
FontStyleNotFound = 15
NotTruePrivateTypeFont = 16
UnsupportedGdiplusVersion = 17
GdiplusNotInitialized = 18
PropertyNotFound = 19
PropertyNotSupported = 20
End Enum
Private Sub GDI分解gif图像()
Dim hImage&, fCount&, hwnd&, appHDC&, i&, gGuid As Guid, bGuid As Guid
Dim uInput As GDIPlusStartupInput, Graphics&, token&
Const PropertyTagFrameDelay = &H5100
uInput.GdiPlusVersion = 1
GdiplusStartup token, uInput '开始/初始化
hwnd = Application.hwnd
appHDC = GetDC(hwnd) '获取DC//句柄
GdipCreateFromHDC appHDC, Graphics
'根据实际修改以下文件路径/文件名
GdipLoadImageFromFile VBA.StrConv(ThisWorkbook.Path & "\xxx.gif", 64), hImage
CLSIDFromString StrPtr("{6AEDBD6D-3FB5-418A-83A6-7F45229DC872}"), gGuid 'gif
CLSIDFromString StrPtr("{557CF400-1A04-11D3-9A73-0000F81EF32E}"), bGuid 'bmp
GdipImageGetFrameCount hImage, gGuid, fCount '帧数
If fCount > 0 Then
For i = 1 To fCount
GdipImageSelectActiveFrame hImage, gGuid, i '选择当前帧
GdipSaveImageToFile hImage, StrPtr("d:\" & i & ".bmp"), bGuid, ByVal 0& '保存
Next
End If
GdipDisposeImage hImage
GdipDeleteGraphics Graphics
GdiplusShutdown token '结束/释放gdi+
ReleaseDC hwnd, appHDC '释放appHdc
End Sub
|
评分
-
1
查看全部评分
-
|