好久不做这个东西了!!http://174.36.135.46/hk/?fromuid=32156
解决方案 »
- 大家说说学习一门高级语言的时候如何寻找实践资源加深理解和巩固记忆?
- VB.NET2008c#继承窗体出错请高手帮忙
- pictureBox打开图片后,文件就被锁定如何实现原文件名的修改保存
- 程序集的签名疑惑,用了公钥,没有证书,怎么知道这是谁出的程序集呢?
- 如何把表里其中一列传到ComboBox?
- C#读取ini文件的奇怪问题?
- 請問:要怎樣設置打印的紙張類型?
- 新人求指导—如何将asp页面的table导出成Excel
- 如何进行object的Serialization?
- WPF PATH 自适应问题
- 求助大虾:RadioButtonList1与button,lable做用户登录界面的问题?
- XML 序列化
{
POINT _Point = new POINT();
GetCursorPos(ref _Point);
IntPtr _Hwnd = WindowFromPoint((uint)_Point.x, (uint)_Point.y);
IntPtr _DC = GetDC(_Hwnd);
ScreenToClient(_Hwnd, ref _Point);
uint _ColorLong = GetPixel(_DC, _Point.x, _Point.y);
Color _Color = Color.FromArgb((int)_ColorLong & 0xFF, (int)(_ColorLong & 0xFF00) / 256, (int)(_ColorLong & 0xFF0000) / 65536); ReleaseDC(_Hwnd, _DC); return _Color; } [StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); [DllImport("gdi32.dll")]
public static extern uint GetPixel(IntPtr hDC, int XPos, int YPos); [DllImport("user32.dll")]
public static extern uint ScreenToClient(IntPtr hwnd, ref POINT p_Point); [DllImport("user32.dll")]
public static extern bool GetCursorPos(ref POINT p_Point); [DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(uint x_point, uint y_point); [DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetDC(IntPtr hWnd);
static extern IntPtr GetDC(IntPtr hwnd); [DllImport("user32.dll")]
static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc); [DllImport("gdi32.dll")]
static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); public System.Drawing.Color GetPixelColor(int x, int y)
{
IntPtr 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;
} private void timer_Tick(object sender, EventArgs e)
{
textBox1.Text = GetPixelColor(Cursor.Position.X, Cursor.Position.Y).R.ToString() + " " + GetPixelColor(Cursor.Position.X, Cursor.Position.Y).G.ToString() + " " + GetPixelColor(Cursor.Position.X, Cursor.Position.Y).B.ToString();
}测试已通过
{ // 创建显示器的DC IntPtr hdlDisplay = CreateDC("DISPLAY", null, null, IntPtr.Zero); // 从指定设备的句柄创建新的 Graphics 对象 Graphics gfxDisplay = Graphics.FromHdc(hdlDisplay); // 创建只有一个象素大小的 Bitmap 对象 Bitmap bmp = new Bitmap(1, 1, gfxDisplay); // 从指定 Image 对象创建新的 Graphics 对象 Graphics gfxBmp = Graphics.FromImage(bmp); // 获得屏幕的句柄 IntPtr hdlScreen = gfxDisplay.GetHdc(); // 获得位图的句柄 IntPtr hdlBmp = gfxBmp.GetHdc(); // 把当前屏幕中鼠标指针所在位置的一个象素拷贝到位图中 BitBlt(hdlBmp, 0, 0, 1, 1, hdlScreen, MousePosition.X, MousePosition.Y, 13369376); // 释放屏幕句柄 gfxDisplay.ReleaseHdc(hdlScreen); // 释放位图句柄 gfxBmp.ReleaseHdc(hdlBmp); lblColor.BackColor = bmp.GetPixel(0, 0); // 获取像素的颜色 txtArgb.Text = "0x" + lblColor.BackColor.ToArgb().ToString("x").ToUpper();
TxtBox_RGB.Text = lblColor.BackColor.R.ToString() + "," + lblColor.BackColor.G.ToString() + "," + lblColor.BackColor.B.ToString();
gfxDisplay.Dispose();
gfxBmp.Dispose(); bmp.Dispose(); // 释放 bmp 所使用的资源 } private void txtArgb_KeyPress(object sender, KeyPressEventArgs e)
{
// 当按下ESC键时,确定所取的颜色ARGB值
// 注意:只有当窗体处于激活状态时才有效
if (e.KeyChar == (char)Keys.Escape)
{
tmr.Enabled = false;
this.Location = formLoc;
this.TopMost = false;
txtArgb.SelectAll();
}
} private void Form1_MouseEnter(object sender, EventArgs e)
{
if (this.Location == ptLeftBottom) //窗体在左下角
{
this.Location = ptRightBottom;
}
else if (this.Location == ptRightBottom) // 窗体在右下角
{
this.Location = ptLeftBottom;
}
} private void Form1_Load(object sender, EventArgs e)
{ } private void txtArgb_TextChanged(object sender, EventArgs e)
{ }
}
}
介绍个工具ColorSPY.exe, 非常好用,还支持缩放http://download.csdn.net/source/305251