ImageGrab.grab(bbox) and Image.getpixel() Used together

后端 未结 1 1678
广开言路
广开言路 2021-01-16 02:19

While using the grab function from PIL.ImageGrab, there\'s a parameter called bbox, which specifies the bounding box of which the screengrab should be taken. And when I want

1条回答
  •  走了就别回头了
    2021-01-16 02:50

    You've made two mistakes:

    1. Since you've specified a bounding box, the resulting image is smaller than your screen resolution. The bounding box is a (left_x, top_y, right_x, bottom_y) tuple, so with the values (500, 500, 600, 700), the image has a width of 100 pixels and a height of 200 pixels.

      That explains why im.getpixel(510, 510) doesn't work - the coordinate 510 is outside of the image.

    2. The getpixel method takes the coordinates as a (x, y) tuple, not as two separate arguments. The correct syntax is im.getpixel((10, 10)).

    0 讨论(0)
提交回复
热议问题