加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-17 00:07:17 所属栏目:大数据 来源:网络整理
导读:问题 here很好地解释了如何将图片框图像转换为VB6中的字节数组. 我想反过来并从字节数组加载我的图片框图像. 我找到了部分解决方案 here,它使用以下代码 Public Function ArrayToPicture(inArray() As Byte,Offset As Long,Size As Long) As IPicture ' func
问题 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读