資源簡介
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?s
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????112640??2017-11-20?15:43??取色值\取色值\bin\Debug\取色值.exe
?????文件??????28160??2017-11-20?15:43??取色值\取色值\bin\Debug\取色值.pdb
?????文件??????11608??2017-12-04?17:16??取色值\取色值\bin\Debug\取色值.vshost.exe
?????文件????????490??2016-03-09?13:48??取色值\取色值\bin\Debug\取色值.vshost.exe.manifest
?????文件???????3645??2017-11-20?15:43??取色值\取色值\Form1.cs
?????文件???????6941??2017-11-20?15:43??取色值\取色值\Form1.Designer.cs
?????文件??????81651??2017-11-20?15:43??取色值\取色值\Form1.resx
?????文件????????789??2017-11-20?14:44??取色值\取色值\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6238??2017-12-04?17:16??取色值\取色值\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????876??2017-12-04?17:16??取色值\取色值\obj\x86\Debug\取色值.csproj.FileListAbsolute.txt
?????文件????????975??2017-11-20?15:43??取色值\取色值\obj\x86\Debug\取色值.csproj.GenerateResource.Cache
?????文件?????112640??2017-11-20?15:43??取色值\取色值\obj\x86\Debug\取色值.exe
?????文件??????50788??2017-11-20?15:43??取色值\取色值\obj\x86\Debug\取色值.Form1.resources
?????文件??????28160??2017-11-20?15:43??取色值\取色值\obj\x86\Debug\取色值.pdb
?????文件????????180??2017-11-20?15:43??取色值\取色值\obj\x86\Debug\取色值.Properties.Resources.resources
?????文件????????490??2017-11-20?14:44??取色值\取色值\Program.cs
?????文件???????1368??2017-11-20?14:44??取色值\取色值\Properties\AssemblyInfo.cs
?????文件???????2870??2017-11-20?14:44??取色值\取色值\Properties\Resources.Designer.cs
?????文件???????5612??2017-11-20?14:44??取色值\取色值\Properties\Resources.resx
?????文件???????1096??2017-11-20?14:44??取色值\取色值\Properties\Settings.Designer.cs
?????文件????????249??2017-11-20?14:44??取色值\取色值\Properties\Settings.settings
?????文件??????50222??2017-11-20?15:43??取色值\取色值\turtle_128px_1167513_easyicon.net.ico
?????文件???????3783??2017-11-20?15:43??取色值\取色值\取色值.csproj
?????文件????????869??2017-11-20?14:44??取色值\取色值.sln
????..A..H.?????18432??2017-12-04?17:51??取色值\取色值.suo
?????目錄??????????0??2017-11-20?14:44??取色值\取色值\obj\x86\Debug\TempPE
?????目錄??????????0??2019-02-22?09:17??取色值\取色值\obj\x86\Debug
?????目錄??????????0??2019-02-22?09:17??取色值\取色值\bin\Debug
?????目錄??????????0??2019-02-22?09:17??取色值\取色值\obj\x86
?????目錄??????????0??2019-02-22?09:17??取色值\取色值\bin
............此處省略7個文件信息
- 上一篇:C#圖片取點獲取對應坐標參數工具
- 下一篇:C# 鋼琴 (PianoDemo)
評論
共有 條評論