基本信息
源码名称:C# 取色工具源代码(RGB)
源码大小:0.09M
文件格式:.rar
开发语言:C#
更新时间:2020-11-04
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
C#屏幕取色器,获取对应点的RGB值,点击空格保存在文本框方便拷贝对应参数值,源代码方便直接拷贝到自身项目。
C#屏幕取色器,获取对应点的RGB值,点击空格保存在文本框方便拷贝对应参数值,源代码方便直接拷贝到自身项目。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 取色值
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("gdi32.dll")]
static public extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
[DllImport("gdi32.dll")]
static public extern IntPtr CreateDC(string driverName, string deviceName, string output, IntPtr lpinitData);
[DllImport("gdi32.dll")]
static public extern bool DeleteDC(IntPtr DC);
string r="";
string g = "";
string b = "";
static public byte GetRValue(uint color)
{
return (byte)color;
}
static public byte GetGValue(uint color)
{
return ((byte)(((short)(color)) >> 8));
}
static public byte GetBValue(uint color)
{
return ((byte)((color) >> 16));
}
static public byte GetAValue(uint color)
{
return ((byte)((color) >> 24));
}
public Color GetColor(Point screenPoint)
{
IntPtr displayDC = CreateDC("DISPLAY", null, null, IntPtr.Zero);
uint colorref = GetPixel(displayDC, screenPoint.X, screenPoint.Y);
DeleteDC(displayDC);
byte Red = GetRValue(colorref);
textBox1.Text = Convert.ToString(Red);
r = Convert.ToString(Red);
byte Green = GetGValue(colorref);
textBox2.Text = Convert.ToString(Green);
g = Convert.ToString(Green);
byte Blue = GetBValue(colorref);
textBox3.Text = Convert.ToString(Blue);
b = Convert.ToString(Blue);
return Color.FromArgb(Red, Green, Blue);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Point pt = new Point(Control.MousePosition.X, Control.MousePosition.Y);
Color cl = GetColor(pt);
panel1.BackColor = cl;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
//if (e.KeyCode == Keys.Space)
//{
// //Point pt = new Point(Control.MousePosition.X, Control.MousePosition.Y);
// //Color cl = GetColor(pt);
// //panel1.BackColor = cl;
// e.Handled = true; //将Handled设置为true,指示已经处理过KeyPress事件
// textBox4.Text = r " " g " " b;
// textBox4.Enabled = true;
//}
}
private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
textBox4.Text = "";
//Point pt = new Point(Control.MousePosition.X, Control.MousePosition.Y);
//Color cl = GetColor(pt);
//panel1.BackColor = cl;
e.Handled = true; //将Handled设置为true,指示已经处理过KeyPress事件
string tex = r "——" g "——" b;
textBox4.Text = tex.TrimStart();
}
}
}
}