using System.Runtime.InteropServices;
private struct POINT
{
private int x;
private int y;
}
static POINT point;
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetDC(int hwnd);
[DllImport("gdi32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetPixel(int hdc, int x, int y);
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int ReleaseDC(int hwnd, int hdc);
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int WindowFromPoint(int x, int y);
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private

这段代码展示了如何使用C#的DllImport导入Windows API函数,实现从屏幕指定位置获取颜色值的功能。通过GetDC、GetPixel、ReleaseDC等函数,可以获取到屏幕像素的颜色,并转化为Color对象返回。
最低0.47元/天 解锁文章
229

被折叠的 条评论
为什么被折叠?



