Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ImageGrab.grabclipboard() on Windows #4615

Merged
merged 3 commits into from
Jun 21, 2020

Conversation

nulano
Copy link
Contributor

@nulano nulano commented May 9, 2020

Helps #4611

Adds support for the following clipboard formats on Windows in addition to the already supported CF_DIB:

  • CF_DIBV5
  • 'PNG' used by e.g. MS Word 2016 and Paint.NET,
  • CF_HDROP used by most browsers (except Chrome), file explorers, etc.

Support for CF_HDROP was already hinted at in the documentation, but there was merely a FIXME in place of the code.

Used format is selected out of available formats based on the priority specified by the clipboard owner.

While I could see the argument that CF_HDROP is more complicated and should therefore only be a fallback, based on my testing, it is almost always the preferred format, and preserves the original image data (e.g. transparency, tags, ...), unlike bitmaps.

@nulano nulano mentioned this pull request May 13, 2020
src/PIL/ImageGrab.py Outdated Show resolved Hide resolved
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
from . import BmpImagePlugin

return BmpImagePlugin.DibImageFile(data)
return None
Copy link
Member

@radarhere radarhere Jun 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might just be a curious question - why change this from return data to return None?

Copy link
Contributor Author

@nulano nulano Jun 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be dead code in both cases, I just think None is a safer fallback then returning undefined data. If I had to guess, the original return was written in anticipation of implementing CF_HDROP support in C code, but I found it easier in Python.

@hugovk hugovk merged commit 7b759e1 into python-pillow:master Jun 21, 2020
@hugovk
Copy link
Member

hugovk commented Jun 21, 2020

Thanks!

@nulano nulano deleted the clipboard-png branch June 27, 2020 15:46
@nulano nulano mentioned this pull request Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants