How do I read a jpg or png from the windows clipboard in python and vice versa?

后端 未结 4 370
慢半拍i
慢半拍i 2020-12-08 03:25

I have an image (jpg, png, etc.) in the windows clipboard. I\'d like to save it to a file. win32clipboard would seem to be the answer, but every example I can find deals wi

4条回答
  •  太阳男子
    2020-12-08 04:02

    The function win32clipboard.GetClipboardData() has a parameter. The default parameter specifies that you want the contents of the clipboard as text. You need to pass in the value that specifies the data format you want the clipboard to give you.

    The standard clipboard data formats are documented here.

    ALSO:

    See here for documentation on EnumClipboardFormats() -- basically, you need code like this (untested) to get the formats that are available currently on the clipboard:

    formats = []
    lastFormat = 0
    while 1:
        nextFormat = win32clipboard.EnumClipboardFormats(lastFormat)
        if 0 == nextFormat:
             # all done -- get out of the loop
             break
        else:
             formats.append(nextFormat)
             lastFormat = nextFormat
    # when you get here, formats contains a list of format codes that
    # you can retrieve from the clipboard right now.
    

提交回复
热议问题