Search code examples
c#dllf#drawpixel

How can I plot pixels onto the screen without WinForms using F#/C#?


I want to know how to get and set pixel that are currently shown on the screen, I'm sure this must be possible I just don't know how. Would I need to use a DLL? I don't have any code to show at this point but I just needed to be pointed in the right direction, I can for the most part port from C# to F# if you can only answer in C#.


Solution

  • Look at this question: How to read screen pixels for an application that is not in the foreground?

    using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
    {
      using (Graphics g = Graphics.FromImage(bmpScreenCapture))
      {
         g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, bmpScreenCapture.Size, CopyPixelOperation.SourceCopy);
      }
      Color c = bmpScreenCapture.GetPixel(x,y);
    }