vb如何读取jpg文件某点的像素值

来源:百度知道 编辑:UC知道 时间:2024/06/02 19:33:53
如果随便给定JPG图片中的某个点的坐标,怎么在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 = H