Failed to save the screenshot and the Image damage
What did you do?
I want to save my desktop screenshot for the image comparison
What did you expect to happen?
I wonder if there's something I should do
What actually happened?
the Image damage!
- OS: macOS mojave 10.14.5
- Python: 3.9.2
- Pillow: 9.0.0
def matchImg():
imgSource = '/Users/shenlilin/Desktop/graphicRecognize/picture/screen.png'
# imgSource = '/Users/panchen/Desktop/git/auto_testing_wireless/graphicRecognize/picture/screen.png'
img = ImageGrab.grab()
# print('img',imgSource,img)
# img.show()
img.save(imgSource)
# 基础图像
imsrc = ac.imread(imgSource)
for x in range(len(sys.argv)):
if x == 0:
continue
imgObj = sys.argv[x]
conf = findTemplate(imsrc, imgObj)
print(conf, end=' ')
Here is the unzipped image. So it is cut off partway through.

If you just run the very simple
from PIL import ImageGrab
ImageGrab.grab().show()
does the image appear correct?
Here is the unzipped image. So it is cut off partway through.
If you just run the very simple
from PIL import ImageGrab ImageGrab.grab().show()does the image appear correct?
This is an occasional problem , So i can't let this problem happen every time. But once that happens I can't go on with the next steps.
This is an occasional problem , So i can't let this problem happen every time. But once that happens I can't go on with the next steps.
How frequently does it seem to occur? Every second time? One in five times? One in ten?
It probably won't help, but could you upload a screenshot from your machine taken with Pillow that is correct, for comparison?
If you just run the very simple
from PIL import ImageGrab ImageGrab.grab().show()does the image appear correct?
This is an occasional problem , So i can't let this problem happen every time. But once that happens I can't go on with the next steps.
At the end of your original post, you have some code that is unrelated to Pillow. It would be nice to confirm that the problem is still there without that extra code.
Running pngcheck over the image you've supplied, I get EOF while reading CRC value.
That makes me think that the problem is not taking the screenshot, but saving it as a PNG. Does your Python code actually finish running, or does it exit?
If you successfully save a screenshot as a PNG, and then in a second script, open up that PNG, try to save it again, does the second script ever fail to save the PNG correctly?
Closing this issue as no feedback has been received.
