新聞| | PChome| 登入
2007-10-25 23:23:28 | 人氣117| 回應0 | 上一篇 | 下一篇
推薦 0 收藏 0 轉貼0 訂閱站台

取得PictureBox內BitMap圖的各個Byte

來源:cww

'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

台長: Kenny
人氣(117) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: 程式設計 |
此分類下一篇:AutoRedraw與Image/Picture屬性的關聯
此分類上一篇:彩色BMP檔轉成灰階

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文