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久,还是没搞清楚怎么用这个函数
展开
 我来答
haotool_bd
2012-05-09
知道答主
回答量:20
采纳率:0%
帮助的人:16.9万
展开全部
//我给你加个注释吧
//获取屏幕指定点的颜色
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;
}
草薙在
2012-04-27 · TA获得超过4795个赞
知道大有可为答主
回答量:6187
采纳率:50%
帮助的人:6237万
展开全部
有必要这么复杂么

var bmp = new Bitmap(你的屏幕尺寸,可以从Screen类获取);
var g = Graphics.FromImage(bmp);
g.CopyFromScreen(你的屏幕尺寸)
bmp有获取像素点的方法
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
田强强112
2012-04-28 · 超过10用户采纳过TA的回答
知道答主
回答量:46
采纳率:0%
帮助的人:27.7万
展开全部
var bmp = new Bitmap(你的屏幕尺寸,可以从Screen类获取);
var g = Graphics.FromImage(bmp);
g.CopyFromScreen(你的屏幕尺寸)
bmp有获取像素点的方法
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式