C#(WinForms)-查找光标的颜色 [英] C# (WinForms) - Find Colour of Cursor
问题描述
我的目标:
- 我希望能够从某些坐标中检索包括光标在内的屏幕上的颜色.
- 换句话说,我想你可以说我想检索光标的颜色(或者至少是光标上的某个点/像素).
我的难处:
- 我已经有一些代码可以从某些坐标中检索屏幕上的颜色,但是我相信它不包含光标.我相信这是因为我使用的方法需要一个屏幕截图(没有光标),并从中读取颜色.
我当前的代码:
public static Color RetrieveColour(Point Coordinates)
{
//Use this 'image' to create a Graphics class.
using (Graphics Destination = Graphics.FromImage(ScreenPixel))
{
//Creates a graphic from the specified handler to a window.
//In this case, it uses a handler which has been initialised to zero.
using (Graphics Source = Graphics.FromHwnd(IntPtr.Zero))
{
//Handler from the source device context.
IntPtr HandlerSourceDC = Source.GetHdc();
//Handler to the destination device context.
IntPtr HandlerDC = Destination.GetHdc();
//BitBlt is responsible for doing the copying.
//Returns a non-zero value for upon success.
int retval = BitBlt(HandlerDC, 0, 0, 1, 1, HandlerSourceDC, Coordinates.X, Coordinates.Y, (int)CopyPixelOperation.SourceCopy);
//Release the handlers.
Destination.ReleaseHdc();
Source.ReleaseHdc();
}
}
//Retrieve the colour of the pixel at the specified coordinates.
return ScreenPixel.GetPixel(0, 0);
}
我可能应该添加,它应该与非Windows游标一起使用.我的意思是指来自其他应用程序的自定义游标(如果这对将来的答案有影响).
I should probably add, it should work with non-Windows cursors. By this I mean custom cursors from other applications (if that has any bearing on future answers).
推荐答案
据我目前所知,唯一能够做到这一点的方法是创建一个可充当用户之间的中介.
As far as I am currently aware, the only way that you'd be able to do this is if you were to create a custom driver that can act as an intermediary between the user.
我还没有读太多,但是您可能想研究这个项目 http://www.codeproject.com/KB/cs/DesktopCaptureWithMouse.aspx?display = Print
I haven't read much of it, but you might want to look into this project http://www.codeproject.com/KB/cs/DesktopCaptureWithMouse.aspx?display=Print
以前发布在这里: C#-捕获鼠标光标图像
这篇关于C#(WinForms)-查找光标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!