0

So I tried using

bmp.GetPixel(-100, 100);

https://learn.microsoft.com/en-us/windows/desktop/api/gdiplusheaders/nf-gdiplusheaders-bitmap-getpixel

But apparently I can't use a negative integer for it, throws out an error. So I then used

GetPixel(-100, 100);

https://learn.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getpixel

And that worked but it's super slow...

Does anyone have a better method to get a pixel's color on a secondary monitor where I need to use a negative number for it's coordinate? I have spent hours trying to figure this out and any help or different methods would be greatly appreciated.

Sorry should have included the code for the screenshot, here it is.

        Bitmap bmp = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
        Graphics graphics = Graphics.FromImage(bmp as Image);
        graphics.CopyFromScreen(-1920, 0, 0, 1080, bmp.Size);

I just want to take a screenshot of the second monitor and save it in a bitmap so that I can search for the pixel faster.

  • You could save the monitor's display to a `Bitmap` and then use `.GetPixel()` on that `Bitmap`. – absoluteAquarian Oct 31 '18 at 13:30
  • [Graphics.CopyFromScreen Method](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.copyfromscreen?view=netframework-4.7.2) might be faster. – 001 Oct 31 '18 at 13:31
  • Tau that's what I tried doing but when I specified the negative coordinate for bmp.GetPixel(-100, 100) where bmp is my saved monitor display, it throws out an exception saying that it has to be a positive integer. Johnny Mopp, I couldn't get that to work either. Damien, I added links to it to hopefully clarify things. – ArcticWolf_11 Oct 31 '18 at 13:49
  • 1
    Can you show us the code you used to get the bitmap from the screen? Yes the screen coordinates will be -100,100 but the Bitmap will always be relative to 0,0. So once you copy it to the bitmap it is offset from 0,0. – Jeff R. Oct 31 '18 at 14:12
  • I should've been more specific with my comment. I'm still saying that you could save the display into a `Bitmap` object, but then use relative positive coordinates (`x` being the screen's width - `100`, `y` not changing). – absoluteAquarian Oct 31 '18 at 16:07
  • @Damien_The_Unbeliever ah alright, I don't use stackoverflow often so I didn't know, thanks. – ArcticWolf_11 Oct 31 '18 at 20:02
  • @JeffR. Added the code Jeff. – ArcticWolf_11 Oct 31 '18 at 20:02
  • @Tau Also how would that work when the pixel is on the second monitor where every X coordinate is negative? – ArcticWolf_11 Oct 31 '18 at 20:03
  • @ArcticWolf_11 if you [store an image of the screen](https://stackoverflow.com/a/363008/8420233) and then save that to a `Bitmap`, then all of the coordinates will be positive. – absoluteAquarian Nov 01 '18 at 13:03
  • @Tau Ah alright, i'll give that a try, thanks! – ArcticWolf_11 Nov 01 '18 at 20:02

0 Answers0