屏幕取色
var currpt = sp.GetCurrentMousePoint();
var pxcolor = sp.GetPixelColorFromPoint(currpt);
var info = new DisplayTextInfo();
info.Message = "x: "+currpt.X+" y: " + currpt.Y+"\nRGB: "+pxcolor.R+"."+pxcolor.G+"."+pxcolor.B;
info.Duration = 1000;
info.MessageAlignment = "left";
info.Location = (currpt.X+10)+','+(currpt.Y-100);
info.MessageFont = new Font("Segoe UI Semibold", 12);
info.BackColor = "black";
info.Padding = 0;
info.ClipToWorkingArea = false;
sp.DisplayText(info);
var chex = "";
while (!(sp.GetKeyState(vk.LBUTTON) & 0x8000)) {
currpt = sp.GetCurrentMousePoint();
pxcolor = sp.GetPixelColorFromPoint(currpt);
pxcolorAbove = sp.GetPixelColorFromPoint(new Point(currpt.X, currpt.Y - 100));
var rhex = Number(pxcolor.R).toString(16);
if (rhex.length < 2) {
rhex = "0" + rhex;
};
var ghex = Number(pxcolor.G).toString(16);
if (ghex.length < 2) {
ghex = "0" + ghex;
};
var bhex = Number(pxcolor.B).toString(16);
if (bhex.length < 2) {
bhex = "0" + bhex;
};
var rhexAbove = Number(pxcolorAbove.R).toString(16);
if (rhexAbove.length < 2) {
rhexAbove = "0" + rhexAbove;
};
var ghexAbove = Number(pxcolorAbove.G).toString(16);
if (ghexAbove.length < 2) {
ghexAbove = "0" + ghex;
};
var bhexAbove = Number(pxcolorAbove.B).toString(16);
if (bhexAbove.length < 2) {
bhexAbove = "0" + bhex;
};
//chex = "#" + rhex + ghex + bhex;
chex = pxcolor.R+","+pxcolor.G+","+pxcolor.B;
info.Message = "x: "+currpt.X+" y: " + currpt.Y;
//RGB
info.Message += "\nAt Cursor - RGB: "+pxcolor.R+","+pxcolor.G+","+pxcolor.B;
//十六进制
//info.Message += "\n" + System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(pxcolor.R, pxcolor.G, pxcolor.B));
//info.Message += "\nAt Cursor - hex: " + chex
//info.Message += "\nAbove (100px) - RGB: "+pxcolorAbove.R+","+pxcolorAbove.G+","+pxcolorAbove.B;
//info.Message += "\nAbove (100px) - hex: #" + rhex + ghex + bhex;
info.Location = (currpt.X+10)+','+(currpt.Y-100);
sp.DisplayTextUpdate(info); //Refresh the existing text and location, instead of closing and reopening the popup
sp.Sleep(10);
}
clip.SetText(chex);
sp.DisplayTextClose();