简体   繁体   English

PIL的.crop返回图像0x0。 指定bbox的ImageGrab.grab也是如此

[英]PIL's .crop returns image 0x0. So does ImageGrab.grab with specified bbox

so I am trying to capture a part of my screen. 所以我试图捕捉屏幕的一部分。 But it returns me 0x0 image. 但它返回我0x0图像。 All my code at the moment is: 目前我所有的代码是:

from PIL import ImageGrab
im = ImageGrab.grab(bbox=(466,789,116,439))
print im
>><PIL.Image._ImageCrop image mode=RGB size=0x0 at 0x1E64120>

Although without specifying bbox 虽然没有指定bbox

im = ImageGrab.grab()
print im
>><PIL.Image.Image image mode=RGB size=1280x1024 at 0x1F33198>

I also tried to take a fullscreen image and then crop it: 我还尝试拍摄全屏图像,然后裁剪它:

bbox=(466,789,116,439)
im = ImageGrab.grab()
print im
im = im.crop((466,789,116,439))
print im
<PIL.Image.Image image mode=RGB size=1280x1024 at 0x1DA41C0>
<PIL.Image._ImageCrop image mode=RGB size=0x0 at 0x1DA4260>

I have literally no idea how it is not working. 我真的不知道它是如何工作的。 Haven't found anyone with the same problem, so here I am. 找不到任何有相同问题的人,所以我在这里。 Thanks in advance 提前致谢

Python 2.7 Python 2.7
PIL 1.1.7 PIL 1.1.7

I was having the same issue with this and realized that the bbox is (start_x, start_y, end_x, end_y) instead of (x, y, width, height) so supposing those parameters are your dimensions just write 我对此有相同的问题,并意识到bbox是(start_x,start_y,end_x,end_y)而不是(x,y,宽度,高度),因此假设这些参数就是您的尺寸,只需编写

im = ImageGrab.grab(bbox=(466,789,582,1228))

and you should have a correctly sized image. 并且您应该具有正确尺寸的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM