c# 返回指点坐标点颜色的代码,请指教
usingSystem;usingSystem.Drawing;usingSystem.Runtime.InteropServices;namespacecs{publi...
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace cs
{
public class cs
{
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int WindowFromPoint(int xPoint, int yPoint);
//指定点窗口的句柄
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetDC(int hwnd);
//获取屏幕DC(这个咧自己想的)
[DllImport("gdi32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetPixel(int hdc, int X, int y);
//获取屏幕指定点的颜色
public Color GetColor(int x, int y)
{
int hdc = GetDC(IntPtr .Zero );
uint pixel = GetPixel(hdc, x, y);
ReleaseDC(IntPtr.Zero, hdc);
Color color = Color.FromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16);
return color;
}
public static void Main()
{
Console.ReadKey ();
}
}
请帮我写全这段代码,我自己写了N久,还是没搞清楚怎么用这个函数 展开
using System.Drawing;
using System.Runtime.InteropServices;
namespace cs
{
public class cs
{
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int WindowFromPoint(int xPoint, int yPoint);
//指定点窗口的句柄
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetDC(int hwnd);
//获取屏幕DC(这个咧自己想的)
[DllImport("gdi32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetPixel(int hdc, int X, int y);
//获取屏幕指定点的颜色
public Color GetColor(int x, int y)
{
int hdc = GetDC(IntPtr .Zero );
uint pixel = GetPixel(hdc, x, y);
ReleaseDC(IntPtr.Zero, hdc);
Color color = Color.FromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16);
return color;
}
public static void Main()
{
Console.ReadKey ();
}
}
请帮我写全这段代码,我自己写了N久,还是没搞清楚怎么用这个函数 展开
展开全部
//我给你加个注释吧
//获取屏幕指定点的颜色
public Color GetColor(int x, int y)
{
int hdc = GetDC(IntPtr .Zero ); //获取屏幕HDC句柄
uint pixel = GetPixel(hdc, x, y); //获取屏幕上(x,y)点的颜色值,这个值是一个32位无符号整数。
ReleaseDC(IntPtr.Zero, hdc); //释放HDC句柄
//Color.FromArgb(red颜色分量,green颜色分量,blue颜色分量)
//pixel & 0x000000FF取低8位red色颜色分量
//(pixel & 0x0000FF00) >> 8 去8-16为green颜色分量,并且右移8位
//其他类似
Color color = Color.FromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16);
return color;
}
//获取屏幕指定点的颜色
public Color GetColor(int x, int y)
{
int hdc = GetDC(IntPtr .Zero ); //获取屏幕HDC句柄
uint pixel = GetPixel(hdc, x, y); //获取屏幕上(x,y)点的颜色值,这个值是一个32位无符号整数。
ReleaseDC(IntPtr.Zero, hdc); //释放HDC句柄
//Color.FromArgb(red颜色分量,green颜色分量,blue颜色分量)
//pixel & 0x000000FF取低8位red色颜色分量
//(pixel & 0x0000FF00) >> 8 去8-16为green颜色分量,并且右移8位
//其他类似
Color color = Color.FromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16);
return color;
}
展开全部
有必要这么复杂么
var bmp = new Bitmap(你的屏幕尺寸,可以从Screen类获取);
var g = Graphics.FromImage(bmp);
g.CopyFromScreen(你的屏幕尺寸)
bmp有获取像素点的方法
var bmp = new Bitmap(你的屏幕尺寸,可以从Screen类获取);
var g = Graphics.FromImage(bmp);
g.CopyFromScreen(你的屏幕尺寸)
bmp有获取像素点的方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var bmp = new Bitmap(你的屏幕尺寸,可以从Screen类获取);
var g = Graphics.FromImage(bmp);
g.CopyFromScreen(你的屏幕尺寸)
bmp有获取像素点的方法
var g = Graphics.FromImage(bmp);
g.CopyFromScreen(你的屏幕尺寸)
bmp有获取像素点的方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询