VB可使用Point方法來獲取圖片指定點(diǎn)的顏色。
新建ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
Point 方法
按照長(zhǎng)整數(shù),返回在 Form 或 PictureBox 上所指定磅的紅-綠-藍(lán) (RGB) 顏色。
語(yǔ)法
object.Point(x, y)
'窗體判色代碼:
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
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) '創(chuàng)建帶有透明通道的ARGB顏色
Dim outcr As Color = Color.FromArgb(R, G, B) '創(chuàng)建不透明的RGB顏色
要使用GetPixel函數(shù)來取得像素的顏色值,代碼如下:
1
2
3
4
5
private void button1_Click(object sender, EventArgs e)
{
Color color = new Bitmap(pictureBox1.Image).GetPixel(10, 10);
MessageBox.Show(color.ToString());
加入一個(gè)TextBox控件,一個(gè)Command控件
代碼:
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) '獲取屏幕的設(shè)備場(chǎng)景
Color = GetPixel(WindowDC, 500, 100) '獲指定點(diǎn)的顏色
'分解RGB顏色值
R = (Color Mod 256) '紅色
b = (Int(Color \ 65536)) '藍(lán)色
G = ((Color - (b * 65536) - R) \ 256) '綠色
Text1.BackColor = RGB(R, G, b)
End Sub
public Color col(string colorName)
{
Type colorType = typeof(Color);
PropertyInfo info = colorType.GetProperty(colorName, BindingFlags.Public | BindingFlags.Static);
if (infos == null)
{
//throw Exception
}
return(Color)info.GetValue(null, null);
}
是這個(gè)意思么?輸入“Red”, 返回Color.Red 區(qū)分大小寫