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

时间:2008-11-10 21:19:21

标签: arrays vb6

我有一个VB6图片框,可以从视频捕获设备中获取图像。

我正在试图弄清楚如何将图片框转换为字节数组。

2 个答案:

答案 0 :(得分:4)

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 :(得分:2)

自从我使用VB6以来已经很长时间了,但据我记忆,您可以将图像序列化为PropertyBag并将内容作为字节数组获取。

我所知道的唯一选择是需要大量使用WinAPI才能完成同样的工作。