语言和图像理解:谁能告诉我用vb取一个点的颜色值的那个函数是什么?谢谢!

来源:百度文库 编辑:高考问答 时间:2024/05/10 14:15:10

Point(x,y)
使用Point方法,窗体判色代码如下
Private Sub Form1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub

PictureBox判断色彩代码:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Picture1.Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub
GOOD LUCK

Point(x,y)

使用Point方法,窗体判色代码:
Private Sub Form1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub

PictureBox判色代码:

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Picture1.Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub

' 全屏幕取色(anbert原创)
' 在窗体上按住鼠标不放,然后可以在整个屏幕移动
' Label控件(就是标签)上会显示取到的颜色,窗口标题显示颜色值
'
' 新建一个窗体,添加一个Label控件,名字叫Label1
' 然后添加以下代码
'
Option Explicit

'声明API
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINT) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINT) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long

'自定义一个类型
Private Type POINT
X As Long
Y As Long
End Type

'取到的颜色保存在这里
Dim theColor As Long

'按下鼠标时指针变成十字型
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = 2
End Sub

'全屏幕取色
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
If Button <> 1 Then Exit Sub
Dim pos As POINT
GetCursorPos pos
Dim hdc As Long, dc As Long
hdc = WindowFromPoint(pos.X, pos.Y)
ScreenToClient hdc, pos
dc = GetDC(hdc)
theColor = GetPixel(dc, pos.X, pos.Y)

Me.Caption = CStr(theColor)
Debug.Print "Color:" & CStr(theColor) & vbCrLf
Label1.BackColor = theColor
End Sub

'松开鼠标时指针变成默认
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = 0
End Sub