Color of a screen pixel: Difference between revisions
Content added Content deleted
m (→{{header|BASIC}}: Doesn't need a function) |
(added c#) |
||
Line 1: | Line 1: | ||
{{task|GUI}}Get color information from an arbitrary pixel on the screen, such as the current location of the mouse cursor |
{{task|GUI}}Get color information from an arbitrary pixel on the screen, such as the current location of the mouse cursor |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<lang AutoHotkey> |
<lang AutoHotkey> |
||
Line 10: | Line 11: | ||
} |
} |
||
</lang> |
</lang> |
||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
{{works with|QuickBasic|4.5}} |
{{works with|QuickBasic|4.5}} |
||
Line 15: | Line 17: | ||
In a graphics mode (for instance, <tt>SCREEN 13</tt> or <tt>SCREEN 12</tt>) |
In a graphics mode (for instance, <tt>SCREEN 13</tt> or <tt>SCREEN 12</tt>) |
||
<lang qbasic>color = point(x, y)</lang> |
<lang qbasic>color = point(x, y)</lang> |
||
=={{header|C sharp|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 csharp> |
Revision as of 01:27, 28 May 2009
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
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
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 csharp>