VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 取得PictureBox内BitMap图的各个Byte
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:14001, 日期:2001-09-17
取得PictureBox内BitMap图的各个Byte


 

注释:Form 中有PictureBox并指定好图形,另一CommandBox

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 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 hBitmap As Long
Dim res As Long
Dim bmp As BITMAP
Dim byteAry() As Byte
Dim totbyte As Long, i As Long
hBitmap = Picture1.Picture.Handle

res = GetObject(hBitmap, Len(bmp), bmp) 注释:取得BitMap的结构

totbyte = bmp.bmWidthBytes * bmp.bmHeight 注释:总共要多少个Byte来存图

ReDim byteAry(totbyte - 1)
注释:将该图全放进ByteAry中
res = GetBitmapBits(hBitmap, totbyte, byteAry(0))

Debug.Print "Total Bytes Copied :"; res
Debug.Print "bmp.bmBits "; bmp.bmBits
Debug.Print "bmp.bmBitsPixel "; bmp.bmBitsPixel 注释:每个Pixel需多少Bits来表现
Debug.Print "bmp.bmHeight "; bmp.bmHeight       注释:bitmap图的高是多少Pixels
Debug.Print "bmp.bmPlanes "; bmp.bmPlanes
Debug.Print "bmp.bmType "; bmp.bmType            
Debug.Print "bmp.bmWidth "; bmp.bmWidth         注释:BitMap图宽为多少pixels     
Debug.Print "bmp.bmWidthBytes "; bmp.bmWidthBytes  注释:每条扫描线需多少Byte来存
End Sub