Skip to content

MacOS with pixel doubling caused ImageGrab Error #118

Closed
@backtraxe

Description

@backtraxe

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,

  1. Check your monitor's real resolution. (For me is 3840x2160)
  2. 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()
  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmacOS

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions