Task

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

The mouse cursor may or may not have to be active in a GUI created by your program. These functions are OS related.




open System.Drawing
open System.Windows.Forms
 
let GetPixel x y =
    use img = new Bitmap(1,1)
    use g = Graphics.FromImage(img)
    g.CopyFromScreen(new Point(x,y), new Point(0,0), new Size(1,1))
    let clr = img.GetPixel(0,0)
    (clr.R, clr.G, clr.B)
 
let GetPixelAtMouse () =
    let pt = Cursor.Position
    GetPixel pt.X pt.Y