?? jpg數(shù)組到pic.bas
字號:
Attribute VB_Name = "jpg數(shù)組到pic"
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Declare Function CLSIDFromString Lib "ole32" (ByVal Str As Long, id As GUID) As Long
Private Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb As Long) As Long
Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, ppstm As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32" (pStream As Any, ByVal lSize As Long, ByVal fRunmode As Long, riid As Any, ppvObj As Any) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
'**************************************************************
' 參數(shù)說明:
'
' bImageData(): 保存圖像信息的字節(jié)數(shù)組。
'
' 返回值:
'
' 返回轉(zhuǎn)換后的 IPictreDisp 對象。
'**************************************************************
Public Function GetPictureFromByteStream(bImageData() As Byte) As IPicture
Dim lngByteCount As Long
Dim hMem As Long
Dim lpMem As Long
Dim IID_IPicture(15) As GUID
Dim IStream As stdole.IUnknown
On Error GoTo Err_Init
lngByteCount = UBound(bImageData) + 1 ' 計算數(shù)組大小
hMem = GlobalAlloc(&H2 Or GMEM_ZEROINIT, lngByteCount) ' 按數(shù)組大小分配一塊內(nèi)存空間
If hMem <> 0 Then
' ' 若分配內(nèi)存成功
lpMem = GlobalLock(hMem) ' 鎖定內(nèi)存, 返回第一塊的指針
If lpMem <> 0 Then
CopyMemory ByVal lpMem, bImageData(0), lngByteCount
Call GlobalUnlock(hMem)
If CreateStreamOnHGlobal(hMem, 1, IStream) = 0 Then
If CLSIDFromString(StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), IID_IPicture(0)) = 0 Then
'If CLSIDFromString(StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), IID_IPicture(0)) = 0 Then
Call OleLoadPicture(ByVal ObjPtr(IStream), lngByteCount, 0, IID_IPicture(0), GetPictureFromByteStream)
End If
End If
End If
End If
GlobalFree hMem
Exit Function
Err_Init:
MsgBox Err.Number & " - " & Err.Description
End Function
'把圖像數(shù)據(jù)存入字節(jié)數(shù)組,按如下調(diào)用即可:
'Set Picture1.Picture = GetPictureFromByteStream(bytData())
'Private Sub Command1_Click()
'Dim a() As Byte
'Open App.Path & "\temp.jpg" For Binary Access Read As #1
' ReDim a(LOF(1))
' Get #1, , a()
'Close #1
'Set Picture1.Picture = GetPictureFromByteStream(a())
'End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -