简体   繁体   English

拾色器-C#

[英]Color Picker - C#

I'm making a color picker on C#, and I want that the GetPixel function, capture all my windows, so I can use to capture any color on my windows, no matters what window is it, (E-mail, image or anything else). 我正在C#上做一个颜色选择器,并且我希望GetPixel函数能够捕获我所有的窗口,所以无论它是什么窗口,我都可以用来捕获窗口上的任何颜色(电子邮件,图像或其他任何东西)其他)。

How can I do that? 我怎样才能做到这一点?

I have a pictureBox to put the color in. 我有一个PictureBox可以放入颜色。

This blog post seems to offer a solution. 这篇博客文章似乎提供了解决方案。 In essence you run the following code to get the color from wherever the mouse is on the screen: 本质上,您可以运行以下代码从屏幕上的任意位置获取颜色:

IntPtr hdc = GetDC(IntPtr.Zero);
uint pixel = GetPixel(hdc, currentPoint.X, currentPoint.Y);
ReleaseDC(IntPtr.Zero, hdc);
Color color = Color.FromArgb((int)(pixel & 0x000000FF),
    (int)(pixel & 0x0000FF00) >> 8,
    (int)(pixel & 0x00FF0000) >> 16);

I'm not sure how much I should copy up here, but if you download the source code from that page, it should answer a bunch of your questions. 我不确定应该在此处复制多少内容,但是如果您从该页面下载源代码,它将回答一些问题。

And, if that does not work, take a look at this answer: https://stackoverflow.com/a/1483963/1043380 而且,如果这不起作用,请查看以下答案: https : //stackoverflow.com/a/1483963/1043380

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM