vb 获取坐标RGB
来源:百度知道 编辑:UC知道 时间:2024/05/05 09:33:29
假如我的picture1控件里有一张图片,如何获取它X,Y坐标上的RGB值??
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Dim color As Long
Dim R As Long, G As Long, B As Long
Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture1.ScaleMode = 3
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
color = GetPixel(Picture1.hdc, X, Y)
R = color And &HFF '分离出红色
G = (color And 65280) \ 256 '分离出绿色
B = (color And &HFF0000) \ 65536 '分离出蓝色
Me.Cls
Print "当前像素RGB(" & R & "," & G & "," & B & ")"
End Sub