从VB6中的字节数组加载图片框图像 [英] Loading a picturebox image from a byte array in VB6

查看:404
本文介绍了从VB6中的字节数组加载图片框图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题此处很好地解释了如何在VB6中将图片框图像转换为字节数组. 我想做相反的事情,并从字节数组中加载我的图片框图像.

The question here explains nicely how to convert a picture box image to a byte array in VB6. I want to do the reverse and load my picture box image from a byte array.

我找到了部分解决方案

I have found a partial solution here which uses the following code

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

如何获取偏移量和尺寸传递给该功能?

How do I get the Offset and Size to pass to this function?

推荐答案

Size参数是组成数组中图像的字节总数,Offset是数据开始处的数组索引,这样一来,一个数组就可以存储多个图像.

The Size argument is the total number of bytes that comprise the image in the array, Offset is the index of the array where the data begins, this allows a single array to store multiple images.

如果数组仅包含单个图像,则将Offset传递给LBound,将Size传递给UBound - LBound + 1.

If the array contains a single image only, pass it's LBound for Offset and UBound - LBound + 1 for Size.

这篇关于从VB6中的字节数组加载图片框图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆