Color of a screen pixel: Difference between revisions

From Rosetta Code
Content added Content deleted
(added c#)
Line 20: Line 20:
=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==


<lang csharp>
<lang csharp>using System;
using System;
using System.Drawing;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms;
Line 32: Line 31:
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(w, h));
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(w, h));


Color color = img.GetPixel(x, y);</lang csharp>
Color color = img.GetPixel(x, y);</lang>

Revision as of 01:27, 28 May 2009

Task
Color of a screen pixel
You are encouraged to solve this task according to the task description, using any language you may know.

Get color information from an arbitrary pixel on the screen, such as the current location of the mouse cursor

AutoHotkey

<lang AutoHotkey> loop, 200 { MouseGetPos, MouseX, MouseY PixelGetColor, color, %MouseX%, %MouseY% TrayTip, color, color at the current cursor is %color%. sleep, 500 } </lang>

BASIC

Works with: QuickBasic version 4.5

In a graphics mode (for instance, SCREEN 13 or SCREEN 12) <lang qbasic>color = point(x, y)</lang>

C#

<lang csharp>using System; using System.Drawing; using System.Windows.Forms;

int w = Screen.PrimaryScreen.Bounds.Width; int h = Screen.PrimaryScreen.Bounds.Height;

Bitmap img = new Bitmap(w, h); Graphics g = Graphics.FromImage(img); g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(w, h));

Color color = img.GetPixel(x, y);</lang>