Closed
Description
In MacOS, turning on pixel doubling will cause a difference between the real resolution and the display resolution, which will affect the screenshots of ImageGrab.
For me, my monitor's real resolution is 3840x2160, after pixel doubling, it becomes 1920x1080, so the use of ImageGrab.grab(bbox=(x1, y1, x2, y2))
caused PIL.UnidentifiedImageError
.
To solve the problem,
- Check your monitor's real resolution. (For me is 3840x2160)
- Check your displayed resolution. (For me is 1920x1080)
import tkinter as tk
root = tk.Tk()
print(root.winfo_screenwidth())
print(root.winfo_screenheight())
root.destroy()
- I use
ImageGrab.grab()
for whole screenshot, then crop it.
gui.py
, line 266
factor = 3840 / 1920 # repalced with your real resolution / displayed resolution
img = ImageGrab.grab()
img = img.crop((x1*factor, y1*factor, x2*factor, y2*factor))
Activity