{"action":"created","issue":{"url":"https://api.github.com/repos/python-pillow/Pillow/issues/1293","repository_url":"https://api.github.com/repos/python-pillow/Pillow","labels_url":"https://api.github.com/repos/python-pillow/Pillow/issues/1293/labels{/name}","comments_url":"https://api.github.com/repos/python-pillow/Pillow/issues/1293/comments","events_url":"https://api.github.com/repos/python-pillow/Pillow/issues/1293/events","html_url":"https://github.com/python-pillow/Pillow/issues/1293","id":89785059,"number":1293,"title":"Problem with saving image from clipboard","user":{"login":"sallyruthstruik","id":1565642,"avatar_url":"https://avatars.githubusercontent.com/u/1565642?v=3","gravatar_id":"","url":"https://api.github.com/users/sallyruthstruik","html_url":"https://github.com/sallyruthstruik","followers_url":"https://api.github.com/users/sallyruthstruik/followers","following_url":"https://api.github.com/users/sallyruthstruik/following{/other_user}","gists_url":"https://api.github.com/users/sallyruthstruik/gists{/gist_id}","starred_url":"https://api.github.com/users/sallyruthstruik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sallyruthstruik/subscriptions","organizations_url":"https://api.github.com/users/sallyruthstruik/orgs","repos_url":"https://api.github.com/users/sallyruthstruik/repos","events_url":"https://api.github.com/users/sallyruthstruik/events{/privacy}","received_events_url":"https://api.github.com/users/sallyruthstruik/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/python-pillow/Pillow/labels/Bug","name":"Bug","color":"fc2929"},{"url":"https://api.github.com/repos/python-pillow/Pillow/labels/Windows","name":"Windows","color":"00bcf2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":37,"created_at":"2015-06-20T15:47:43Z","updated_at":"2016-04-06T12:52:55Z","closed_at":null,"body":"Hello,\r\n\r\nI have Windows 8 x64 system and installed Pillow version 2.8.2\r\nI'm trying to grab image from clipboard. I press \"Alt+PrtSc\" and then call grabclipboard function, and get such error:\r\n```{python}\r\nImageGrab.grabclipboard()\r\n---------------------------------------------------------------------------\r\nIOError                                   Traceback (most recent call last)\r\n<ipython-input-2-c8274e888e6c> in <module>()\r\n      1 from PIL import ImageGrab\r\n      2 \r\n----> 3 ImageGrab.grabclipboard()\r\n\r\nC:\\Anaconda\\lib\\site-packages\\PIL\\ImageGrab.pyc in grabclipboard()\r\n     49         from PIL import BmpImagePlugin\r\n     50         import io\r\n---> 51         return BmpImagePlugin.DibImageFile(io.BytesIO(data))\r\n     52     return data\r\n\r\nC:\\Anaconda\\lib\\site-packages\\PIL\\ImageFile.pyc in __init__(self, fp, filename)\r\n     95 \r\n     96         try:\r\n---> 97             self._open()\r\n     98         except IndexError as v:  # end of data\r\n     99             if Image.DEBUG > 1:\r\n\r\nC:\\Anaconda\\lib\\site-packages\\PIL\\BmpImagePlugin.pyc in _open(self)\r\n    204 \r\n    205     def _open(self):\r\n--> 206         self._bitmap()\r\n    207 \r\n    208 #\r\n\r\nC:\\Anaconda\\lib\\site-packages\\PIL\\BmpImagePlugin.pyc in _bitmap(self, header, offset)\r\n    145                     raw_mode = MASK_MODES[(file_info['bits'], file_info['rgb_mask'])]\r\n    146                 else:\r\n--> 147                     raise IOError(\"Unsupported BMP bitfields layout\")\r\n    148             else:\r\n    149                 raise IOError(\"Unsupported BMP bitfields layout\")\r\n\r\nIOError: Unsupported BMP bitfields layout\r\n```\r\n\r\nBut if I call ImageGrab.grab function, screenshot(of whole screen) is saved properly. "},"comment":{"url":"https://api.github.com/repos/python-pillow/Pillow/issues/comments/206356793","html_url":"https://github.com/python-pillow/Pillow/issues/1293#issuecomment-206356793","issue_url":"https://api.github.com/repos/python-pillow/Pillow/issues/1293","id":206356793,"user":{"login":"wiredfool","id":19792,"avatar_url":"https://avatars.githubusercontent.com/u/19792?v=3","gravatar_id":"","url":"https://api.github.com/users/wiredfool","html_url":"https://github.com/wiredfool","followers_url":"https://api.github.com/users/wiredfool/followers","following_url":"https://api.github.com/users/wiredfool/following{/other_user}","gists_url":"https://api.github.com/users/wiredfool/gists{/gist_id}","starred_url":"https://api.github.com/users/wiredfool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wiredfool/subscriptions","organizations_url":"https://api.github.com/users/wiredfool/orgs","repos_url":"https://api.github.com/users/wiredfool/repos","events_url":"https://api.github.com/users/wiredfool/events{/privacy}","received_events_url":"https://api.github.com/users/wiredfool/received_events","type":"User","site_admin":false},"created_at":"2016-04-06T12:52:55Z","updated_at":"2016-04-06T12:52:55Z","body":"Ok, I think this patch should do it, where the previous one would only work if the first pixel color was 0x696969.\r\n\r\n```\r\ndiff --git a/PIL/BmpImagePlugin.py b/PIL/BmpImagePlugin.py\r\nindex e398445..a3e39c1 100644\r\n--- a/PIL/BmpImagePlugin.py\r\n+++ b/PIL/BmpImagePlugin.py\r\n@@ -109,7 +109,11 @@ class BmpImageFile(ImageFile.ImageFile):\r\n                         for idx, mask in enumerate(['r_mask', 'g_mask', 'b_mask', 'a_mask']):\r\n                             file_info[mask] = i32(header_data[36+idx*4:40+idx*4])\r\n                     else:\r\n-                        for mask in ['r_mask', 'g_mask', 'b_mask', 'a_mask']:\r\n+                        # 40 byte headers only have the three components in the bitfields masks,\r\n+                        # ref: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx\r\n+                        # See also https://github.com/python-pillow/Pillow/issues/1293\r\n+                        file_info['a_mask'] = 0x0\r\n+                        for mask in ['r_mask', 'g_mask', 'b_mask']:\r\n                             file_info[mask] = i32(read(4))\r\n                     file_info['rgb_mask'] = (file_info['r_mask'], file_info['g_mask'], file_info['b_mask'])\r\n                     file_info['rgba_mask'] = (file_info['r_mask'], file_info['g_mask'], file_info['b_mask'], file_info['a_mask'])\r\n```"}}