Skip to content

3.2.0 clipboard image corrupted when saved to png #1811

Closed

Description

@techtonik

This is a continuation after #1810 is fixed.

What did you do?

1 open mspaint
2 alt+prtscr
3 run the code

import sys
from PIL import ImageFile
from PIL import ImageGrab

# #1810 workaround
ImageFile.LOAD_TRUNCATED_IMAGES = True

im = ImageGrab.grabclipboard()
if im is None:
  sys.exit('Error: No image data in clipboard')
im.save('save.bmp', 'BMP')
im.save('save.png', 'PNG')

What did you expect to happen?

BMP and PNG to be the same.

What actually happened?

BMP:
image

PNG:
save

What versions of Pillow and Python are you using?

Pillow 3.2.0, Python 2.7, Vista 32.

Activity

  1. radarhere commented on Apr 6, 2016

    @radarhere
    Member

    If you open the BMP with Pillow, and try to save it as a PNG, is the result the same as the original PNG? Quite possibly the answer is no, it's just that if the answer were yes, then sharing the BMP here would mean that testers on any platform could reproduce the issue.

  2. wiredfool commented on Apr 6, 2016

    @wiredfool
    Member

    I think that this and #1810 are both the same as #1293, since there is an error in the interpretation of the BMP header in the DIB in memory.

    The best debugging for it is going to be to get dumps of the raw data from the imageGrab function, as noted here: #1293 (comment)

  3. hugovk commented on Apr 6, 2016

    @hugovk
    Member

    PR #1813 is merged, so this should be fixed too.

  4. wiredfool commented on Apr 6, 2016

    @wiredfool
    Member

    Please check the fix, there may be other stuff hiding in there

  5. techtonik commented on Apr 6, 2016

    @techtonik
    ContributorAuthor

    Are there any Windows builds that could be installed?

  6. techtonik commented on Apr 7, 2016

    @techtonik
    ContributorAuthor

    @wiredfool is it possible to release 3.2.1 with those fixes?

  7. techtonik commented on Apr 7, 2016

    @techtonik
    ContributorAuthor

    Saved .bmp looks fine, but .png now has a different transparency problem:

    save

  8. wiredfool commented on Apr 7, 2016

    @wiredfool
    Member

    Can you dump the raw bytes from within the ImageGrab.grabclipboard()? As well as what you're seeing from the BMP and the PNG?

  9. techtonik commented on Apr 7, 2016

    @techtonik
    ContributorAuthor

    Attach contains all three files 1811alphabugs.zip

  10. wiredfool commented on Apr 9, 2016

    @wiredfool
    Member

    It looks like the data that's in the alpha channel is not an alpha or transparency mask, it's likely some sort of active area mask, or highlighting, or something. In this case, it's coming up like this:

    alpha

  11. techtonik commented on Apr 16, 2016

    @techtonik
    ContributorAuthor

    This is how inactive window looks like:

    image

    So that mask are probably RGB pixels that are applied with addition or some other algorithm.

    Another things that it is not clear why BMP is saved ok.

  12. wiredfool commented on Apr 19, 2016

    @wiredfool
    Member

    The reason that the BMP is ok is that it's loaded into pillow as RGB, so the funky mask is ignored. So, the BMP is probably broken, and the png is as well.

  13. wiredfool commented on May 5, 2016

    @wiredfool
    Member

    Fix merged in #1847

  14. techtonik commented on May 5, 2016

    @techtonik
    ContributorAuthor

    Need #1815 to be merged to be able to test this.

  15. techtonik commented on May 5, 2016

    @techtonik
    ContributorAuthor

    This hints that egg can be converted to wheel:

    wget https://ci.appveyor.com/api/buildjobs/2lt1ejrowq9eyw5x/artifacts/Pillow-3.3.0.dev0-py2.7-win32.egg
    pip install wheel
    python -m wheel convert Pillow-3.3.0.dev0-py2.7-win32.egg 
    pip install Pillow-3.3.0.dev0-cp27-none-win32.whl -U
    

    That works fine. Thanks.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions