大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
加入一个TextBox控件,一个Command控件
创新互联公司是一家专业提供相山企业网站建设,专注与网站设计、成都网站建设、H5技术、小程序制作等业务。10年已为相山众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。
代码:
Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Private Sub Command1_Click()
Dim Color As Long
WindowDC = GetWindowDC(0) '获取屏幕的设备场景
Color = GetPixel(WindowDC, 500, 100) '获指定点的颜色
'分解RGB颜色值
R = (Color Mod 256) '红色
b = (Int(Color \ 65536)) '蓝色
G = ((Color - (b * 65536) - R) \ 256) '绿色
Text1.BackColor = RGB(R, G, b)
End Sub
R/G/B值最小是0最大是255属Byte值类型
Dim
cr
As
Color
=
控件.BackColor
'获取控件背景色
Dim
alpha
As
Byte
=
cr.A
'透明度
Dim
R
As
Byte
=
cr.R
'R值
Dim
G
As
Byte
=
cr.G
'G值
Dim
B
As
Byte
=
cr.B
'B值
Dim
outAcr
As
Color
=
Color.FromArgb(alpha,
R,
G,
B)
'创建带有透明通道的ARGB颜色
Dim
outcr
As
Color
=
Color.FromArgb(R,
G,
B)
'创建不透明的RGB颜色
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim GetColor As Color = CType(PictureBox1.Image, Bitmap).GetPixel(e.X, e.Y)
TextBox3.Text = GetColor.B.ToString
TextBox2.Text = GetColor.G.ToString
TextBox1.Text = GetColor.R.ToString
End Sub