VB 如何把picturebox中每个点的颜色保存到数组
请注意,不要point那种一个点一个点扫描的方法,太慢了,我这种好像有点问题PrivateDeclareFunctionGetBitmapBitsLib"gdi32"(B...
请注意,不要point那种一个点一个点扫描的方法,太慢了,我这种好像有点问题
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
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 Sub Command1_Click()
Dim PicInof As BITMAP
Picture2.Picture = LoadPicture("C:\Documents and Settings\Administrator\My Documents\ptpic.php.gif")
GetObject (Picture1.Image), Len(PicInof), PicInof
BytesPerPixel = PicInof.bmBitsPixel
ReDim TImage(PicInof.bmWidthBytes * PicInof.bmHeight) As Long 'PicInof.bmWidth - 1, PicInof.bmHeight - 1)
GetBitmapBits Picture2.Image, PicInof.bmWidthBytes * PicInof.bmHeight, TImage(0)
End Sub 展开
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
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 Sub Command1_Click()
Dim PicInof As BITMAP
Picture2.Picture = LoadPicture("C:\Documents and Settings\Administrator\My Documents\ptpic.php.gif")
GetObject (Picture1.Image), Len(PicInof), PicInof
BytesPerPixel = PicInof.bmBitsPixel
ReDim TImage(PicInof.bmWidthBytes * PicInof.bmHeight) As Long 'PicInof.bmWidth - 1, PicInof.bmHeight - 1)
GetBitmapBits Picture2.Image, PicInof.bmWidthBytes * PicInof.bmHeight, TImage(0)
End Sub 展开
展开全部
GetObject (Picture1.Image), Len(PicInof), PicInof
执行成功以后PicInof.bmBits就是图像数据的指针了,再根据PicInof.bmWidthBytes * PicInof.bmHeight算出长度,映射到SAFEARRAY 或者 CopyMemory到数组里.
执行成功以后PicInof.bmBits就是图像数据的指针了,再根据PicInof.bmWidthBytes * PicInof.bmHeight算出长度,映射到SAFEARRAY 或者 CopyMemory到数组里.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
修改如下:
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
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 Sub Command1_Click()
Dim PicInof As BITMAP
Dim BytesPerPixel As Long
Picture2.Picture = LoadPicture("C:\Documents and Settings\Administrator\My Documents\ptpic.php.gif")
GetObject (Picture2.Image), Len(PicInof), PicInof
BytesPerPixel = PicInof.bmBitsPixel
ReDim TImage(PicInof.bmWidthBytes * PicInof.bmHeight) As Byte 'PicInof.bmWidth - 1, PicInof.bmHeight - 1)
GetBitmapBits Picture2.Image.Handle, PicInof.bmWidthBytes * PicInof.bmHeight, TImage(0)
End Sub
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
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 Sub Command1_Click()
Dim PicInof As BITMAP
Dim BytesPerPixel As Long
Picture2.Picture = LoadPicture("C:\Documents and Settings\Administrator\My Documents\ptpic.php.gif")
GetObject (Picture2.Image), Len(PicInof), PicInof
BytesPerPixel = PicInof.bmBitsPixel
ReDim TImage(PicInof.bmWidthBytes * PicInof.bmHeight) As Byte 'PicInof.bmWidth - 1, PicInof.bmHeight - 1)
GetBitmapBits Picture2.Image.Handle, PicInof.bmWidthBytes * PicInof.bmHeight, TImage(0)
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询