从VB6中的字节数组加载图片框图像

问题 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&,aGUID(0),ArrayToPicture)
            End If
        End If
    End If
End Function

如何将偏移量和大小传递给此函数

Size参数是组成数组中图像的总字节数,Offset是数据开始的数组的索引,这允许单个数组存储多个图像.

如果数组只包含一个图像,则传递它的LBound为Offset和UBound – LBound 1为Size.

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...