急求一段代码,读取bmp的rgb值

对于图像的编程处理不很了解,急用,求高手赐教

读取8bit的bmp各个像素点的rgb值,并保存下来

只需要可以做演示作用就行了,控制台应用即可

如果您的时间充裕,可以给出方便批量读取保存的程序更好

非常感谢!

1 个回答

VB 获取图片某点的颜色值
'需控件:Picture1、Label1、Label2

Private Sub Form_Load()
Label1.Width = Me.Width
Label1.Caption = "在图片框上移动鼠标,可查看某个点的颜色值"
Picture1.ScaleMode = vbPixels '设置图片框的单位为:像素
'假设有图片:C:\My1.jpg
'图片类型为 bmp ico rle wmf emf GIF jpg 皆可
Picture1.Picture = LoadPicture("C:\My1.jpg")
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Se As Long, R As Long, G As Long, B As Long
Se = Picture1.Point(X, Y) '获得像素点 x,y 的颜色值
Label2.BackColor = Se '设置 Label2 的背景色为 Se
Call GetRGB(Se, R, G, B) '将颜色值 Se 分解为红、绿、蓝
Label1.Caption = "当前像素点 " & X & "," & Y & " 的颜色(红绿蓝):" & R & "," & G & "," & B
End Sub

Private Sub GetRGB(Se As Long, R As Long, G As Long, B As Long)
Dim xx As String

xx = Hex(Se)
R = Len(xx)
If R < 6 Then xx = String(6 - R, "0") & xx

B = "&H" & Left(xx, 2)
G = "&H" & Mid(xx, 3, 2)
R = "&H" & Mid(xx, 5, 2)
End Sub