Improve ImageGrab.grabclipboard() on Windows by nulano · Pull Request #4615 · python-pillow/Pillow

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.