请教:如何获取24位BMP图片的RGB分量,我现在有一24位的BMP图片,现在想要将此图片的各个像素的RGB值保存为(R,G,B)形式的txt文本文档,如何实现?
请教:如何获取24位BMP图片的RGB分量,我现在有一24位的BMP图片,现在想要将此图片的各个像素的RGB值保存为(R,G,B)形式的txt文本文档,如何实现?
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 Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) 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 Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Const DIB_RGB_COLORS = 0 ' color table in RGBs
Private Sub Command1_Click()
Dim BITMAP As BITMAPINFO
Dim ImgData() As Byte
Dim lIndex As Long
Dim a As String
a = Text2.Text
With BITMAP
.bmiHeader.biSize = 40
End With
If GetDIBits(picture1.hdc, picture1.Picture.Handle, 0, 0, 0, BITMAP, DIB_RGB_COLORS) <> 0 Then '获取图像位图数据大小
ReDim ImgData(BITMAP.bmiHeader.biSizeImage / 3, 2)
If GetDIBits(picture1.hdc, picture1.Picture.Handle, 0, BITMAP.bmiHeader.biHeight - 1, ImgData(0, 0), BITMAP, DIB_RGB_COLORS) <> 0 Then
'ImgData(X,0)中保存的为蓝色分量值
'ImgData(X,1)中保存的为绿色分量值
'ImgData(X,2)中保存的为红色分量值
Point_x.Text = BITMAP.bmiHeader.biWidth
Point_y.Text = BITMAP.bmiHeader.biHeight
List1.Clear
For lIndex = 0 To BITMAP.bmiHeader.biSizeImage / 3
List1.AddItem ImgData(lIndex, 2) & ";" & ImgData(lIndex, 1) & ";" & ImgData(lIndex, 0)
Next
End If
End If
End Sub
这样list1中显示是否是我要的东西呢?但是好像又是不对的,请指教