API要命都學不會啊
‘API的宣告
Private DeclareFunction GetObject Lib "gdi32" Alias "GetObjectA" (ByValhObject As Long, ByVal nCount As Long, lpObject As Any) As Long ‘得到指定圖形物件的資訊
Private DeclareFunction GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByValdwCount As Long, lpBits As Any) As Long ‘將指定位圖的位拷貝到緩沖區里
private TypeBITMAP ‘Bitmap 的宣告,不需要深入了解
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Dim hBitmap AsLong
Dim res As Long
Dim bmp As BITMAP
Dim byteBry() As Byte ' 定義一個陣列
Dim totbyte As Long, i As Long
hBitmap = SrcPic.Picture.Handle
res = GetObject(hBitmap, Len(bmp), bmp) ' 取得BitMap的結構
totbyte = bmp.bmWidthBytes * bmp.bmHeight ' 總共要多少個Byte來存圖
ReDim byteBry(totbyte - 1) ' 重新定義陣列
res = GetBitmapBits(hBitmap, totbyte, byteBry(0)) ' 將該圖放在ByteBry中
List1.AddItem "圖片Bits: " + CStr(bmp.bmBitsPixel) ' 每個像素所占的位
List1.AddItem "圖片高度: " + CStr(bmp.bmHeight) ' 原圖的高
List1.AddItem "圖片寬度: " + CStr(bmp.bmWidth) ' 原圖的
uj5u.com熱心網友回復:
高手?大神?在哪兒?uj5u.com熱心網友回復:
位圖檔案頭有規定的格式,也就是在 BITMAP 型別中定義的那樣。這個型別是微軟的公版 API 介面型別。原型是:Public Type BITMAP '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
注意,private TypeBITMAP 應為 Private Type BITMAP(注意空格)。
GetObject 是一個 API 函式:
Public Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
它可以依指定的物件句柄從物件中獲取 BITMAP 型別資訊。
GetBitmapBits 是另一個 API 函式:
Public Declare Function GetBitmapBits Lib "gdi32" Alias "GetBitmapBits" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
它可以取回物件的像素。
uj5u.com熱心網友回復:
樓主的代碼確實沒能得到位圖的資訊。uj5u.com熱心網友回復:
照葫蘆畫瓢...........uj5u.com熱心網友回復:
如果樓主想獲得的僅僅是BMP格式的影像資訊,我這里有個完整的示例可能更清晰。用到了BMP檔案完整的檔案頭資訊:
Public Type bmpHead
bmpFlg1 As Byte '1+0=1 '"B"
bmpFlg2 As Byte '1+1=2 '"M"
FileSize As Long '4+2=6 '檔案總長
Reserved1 As Integer '2+6=8 '保留(==0)
Reserved2 As Integer '2+8=10 '保留(==0)
bmpDataOffset As Long '4+10=14 '影像像素編碼資料的偏移
bmpInfoSize As Long '4+14=18 '影像基本資訊位元組數
bmpWidth As Long '4+18=22 '影像寬
bmpHeight As Long '4+22=26 '影像高
bmpPlanes As Integer '2+26=28 '調色板層數
PixelBits As Integer '2+28=30 '每個像素對應的bit數
Compression As Long '4+30=34 '壓縮方式(0=未壓縮)
bmpDataSize As Long '4+34=38 '影像資料的位元組數
XPelsPerM As Long '4+38=42 'X決議度
YPelsPerM As Long '4+42=46 'Y決議度
UsedColor As Long '4+46=50 '時機使用的顏色數
ImportColor As Long '4+50=54 '顯示時重要的顏色數
End Type
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/113912.html
標籤:API
上一篇:實作多表單同步移動
