2个回答
展开全部
如何获取图片某点的颜色值
'需控件: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
'需控件: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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询