如何将数组里的字节流图片显示在界面上?
如何将数组里的字节流图片显示在界面上?
[解决办法]
9个步骤
1.引用olelib.tlb
2.模块中贴入下面代码:
Private Const GMEM_MOVEABLE = &H2
Private Const GMEM_ZEROINIT = &H40
Private Const GHND = (GMEM_MOVEABLE Or GMEM_ZEROINIT)
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem 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 Const PictureID = &H746C&
Private Type PictureHeader
Magic As Long
Size As Long
End Type
Public Function Array2Picture(aBytes() As Byte) As IPicture
Dim oIPS As IPersistStream
Dim oStream As IStream
Dim hGlobal As Long
Dim LPTR As Long
Dim lSize As Long
Dim Hdr As PictureHeader
lSize = UBound(aBytes) - LBound(aBytes) + 1
hGlobal = GlobalAlloc(GHND, lSize + Len(Hdr))
If hGlobal Then
LPTR = GlobalLock(hGlobal)
Hdr.Magic = PictureID
Hdr.Size = lSize
MoveMemory ByVal LPTR, Hdr, Len(Hdr)
MoveMemory ByVal LPTR + Len(Hdr), aBytes(0), lSize
GlobalUnlock hGlobal
Set oStream = CreateStreamOnHGlobal(hGlobal, True)
Set Array2Picture = New StdPicture
Set oIPS = Array2Picture
oIPS.Load oStream
Set oStream = Nothing
End If
End Function
3.用Array2Picture函数把字节流转换成图片
4.显示在界面上就不用说了吧
5.收工
6.下班
7.吃饭
8.泡mm 聊天
9.睡觉
[解决办法]
UP