C\#화면 마우스 좌표 점 색상 간단하게 가 져 오 는 방법 소개

api 함수:

1.[DllImport("user32.dll")]//
2.private static extern IntPtr GetDC(IntPtr hwnd);//
3.[DllImport("gdi32.dll")]//
4.private static extern int GetPixel(IntPtr hdc, Point p);
주요 방법:

Timer tim = new Timer();
tim.Interval = 1;
tim.Tick += delegate
{
Point p = new Point(MousePosition.X, MousePosition.Y);//
IntPtr hdc = GetDC(new IntPtr(0));// (0 )
int c = GetPixel(hdc, p);//
int r = (c & 0xFF);// R
int g = (c & 0xFF00) / 256;// G
int b = (c & 0xFF0000) / 65536;// B
pictureBox1.BackColor = Color.FromArgb(r, g, b);
};
tim.Start();
효과 데모:

좋은 웹페이지 즐겨찾기