在VB6中将图片框图像像素转换为字节数组

4
我有一个VB6图片框,它从视频捕获设备获取图像。
我正在尝试找出如何将图片框转换为字节数组。
2个回答

5
Private Type BITMAP
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Private Sub GetPictureBytes()
  Dim PicBits() As Byte, PicInfo As BITMAP

  GetObject Picture1.Picture, Len(PicInfo), PicInfo

  ReDim PicBits((PicInfo.bmWidth * PicInfo.bmHeight * 3) - 1) As Byte

  GetBitmapBits Picture1.Picture, UBound(PicBits), PicBits(0)
End Sub

1
做这个的相反操作怎么样?你能发布一下propertybag的代码吗? - Smith
我已经在这里提问了:http://stackoverflow.com/questions/26442660/loading-a-picturebox-image-from-a-byte-array-in-vb6 - Kirsten
这将仅检索位图位,而不是位图信息和头。 - Bernardo Ramos
我在Stack Overflow上发布了一个问题,询问如何将包括头文件在内的整个位图转换为字节数组。链接在这里: https://stackoverflow.com/questions/26442660/loading-a-picturebox-image-from-a-byte-array-in-vb6 - JonN

2

我很久没用VB6了,但据我所知,你可以将图像序列化为 PropertyBag 并将内容作为字节数组获取。

我所知道的唯一替代方法需要大量使用WinAPI来完成相同的任务。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接