Skip to content

Instantly share code, notes, and snippets.

@owlscatcher
Created November 18, 2019 04:36
Show Gist options
  • Save owlscatcher/d3b81ef9004b76cfb25329abf63e2d53 to your computer and use it in GitHub Desktop.
Save owlscatcher/d3b81ef9004b76cfb25329abf63e2d53 to your computer and use it in GitHub Desktop.
Return HEX color code.
using System;
using System.Drawing;
using System.Windows.Forms;
class Program
{
static Color GetPixel(Point position)
{
using (var bitmap = new Bitmap(1, 1))
{
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(position, new Point(0, 0), new Size(1, 1));
}
return bitmap.GetPixel(0, 0);
}
}
static void Main()
{
Console.WriteLine(GetPixel(Cursor.Position));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment