简单的屏幕取色器
来源:互联网 发布:c语言判断质数的程序 编辑:程序博客网 时间:2024/05/29 14:41
运行效果截图:
后台代码:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;namespace ColorPicker{ public partial class ColorPickerSimple : Form { #region 引入外部方法 //GetDC,获取DC(设备环境) [DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)] private static extern int GetDC(int hwnd); //GetPixel,获取像素点 [DllImport("gdi32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)] private static extern int GetPixel(int hdc, int X, int y); //ReleaseDC,释放DC [DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)] //确定坐标 private static extern int ReleaseDC(int hwnd, int hdc); #endregion #region 字段 //R、G、B int blue; int green; int red; //指定设备环境(句柄为0则为桌面) int hD; //颜色信息 int c; //鼠标所在处坐标点 int a; int b; #endregion public ColorPickerSimple() { InitializeComponent(); } #region 窗体事件 /// <summary> /// 窗体加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ColorPickerSimple_Load(object sender, EventArgs e) { txtR.ReadOnly = true; txtG.ReadOnly = true; txtB.ReadOnly = true; txtColor.ReadOnly = true; timer1.Enabled = true; } #endregion #region 获取颜色 /// <summary> /// Timer事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { //获取鼠标所在处的坐标 a = System.Windows.Forms.Control.MousePosition.X; b = System.Windows.Forms.Control.MousePosition.Y; //获取DC,设备环境(桌面) hD = GetDC(0); //获取颜色值 c = GetPixel(hD, a, b); //释放DC ReleaseDC(0, hD); //由颜色值计算R、G、B值 red = c % 256; green = (c / 256) % 256; blue = (c / 256 / 256) % 256; //显示颜色分值 txtR.Text = Convert.ToString(red); txtG.Text = Convert.ToString(green); txtB.Text = Convert.ToString(blue); //显示拾取的颜色 Color color = Color.FromArgb(red, green, blue); txtColor.BackColor = color; } #endregion }}
- 简单的屏幕取色器
- 简单的屏幕截图
- 简单的屏幕输出
- 屏幕抓取的简单实现
- 最简单的屏幕OCR文字识别
- 最简单的屏幕OCR文字识别
- 最简单的屏幕OCR文字识别
- windows屏幕抓取的简单源代码
- 最简单的屏幕OCR文字识别
- Java实现简单的屏幕抓图
- 如何:定义简单的 Silverlight 初始屏幕
- 屏幕触发事件onTouchEvent的简单使用
- 最简单的屏幕截屏
- 简单的屏幕开发实例-ABAP
- 一个简单的屏幕保护例子
- android简单可操作的屏幕适配
- 实现一个简单的屏幕截图程序
- ios 简单的使用按比例自适应屏幕
- 类的继承
- 你动了谁的奶酪?——软件过程改进第二阶段的工作-部门规划
- 第八周实验报告2
- oracle ORA-03113 错误
- ora-01950 对表空间无权限
- 简单的屏幕取色器
- 数据库关联映射建表图示(一对多、多对多)
- 河北软件职业技术学院换届选举圆满成功
- grub引导文件损坏进不了系统
- 数组和指针
- 使用eclipse export打jar包,web工程使用*读取配置读不到的问题解决方法
- linux root用户密码忘记了怎么办
- PE系统下安装win7 64位系统
- 第八周任务一1