【发布时间】:2014-12-14 01:52:54
【问题描述】:
问题here很好地解释了如何在VB6中将图片框图像转换为字节数组。 我想做相反的事情并从字节数组中加载我的图片框图像。
我找到了一个部分解决方案 here,它使用以下代码
Public Function ArrayToPicture(inArray() As Byte, Offset As Long, Size As Long) As IPicture
' function creates a stdPicture from the passed array
' Offset is first item in array: 0 for 0 bound arrays
' Size is how many bytes comprise the image
Dim o_hMem As Long
Dim o_lpMem As Long
Dim aGUID(0 To 3) As Long
Dim IIStream As IUnknown
aGUID(0) = &H7BF80980 ' GUID for stdPicture
aGUID(1) = &H101ABF32
aGUID(2) = &HAA00BB8B
aGUID(3) = &HAB0C3000
o_hMem = GlobalAlloc(&H2&, Size)
If Not o_hMem = 0& Then
o_lpMem = GlobalLock(o_hMem)
If Not o_lpMem = 0& Then
CopyMemory ByVal o_lpMem, inArray(Offset), Size
Call GlobalUnlock(o_hMem)
If CreateStreamOnHGlobal(o_hMem, 1&, IIStream) = 0& Then
Call OleLoadPicture(ByVal ObjPtr(IIStream), 0&, 0&, aGUID(0), ArrayToPicture)
End If
End If
End If
End Function
如何获取偏移量和大小以传递给此函数?
【问题讨论】:
-
尝试 0 和 ubound(yourarray) 告诉它整个数组就是图像
-
我使用了 Offset = LBound(Bytear()) 和 size = UBound(Bytear()) - LBound(Bytear()) +1 它似乎工作,我想知道为什么样本不只是去做?想写下你的答案吗?
标签: vb6 picturebox