0

Using Python 3.4.0 in Windows 7, I've managed to copy a single image to clipboard thanks to this question.

Now I want to copy multiple images at the same time. I don't understand much of what is happening in this code, so I'm unable to modify it. Any ideas?

My code:

    msvcrt = ctypes.cdll.msvcrt
    kernel32 = ctypes.windll.kernel32
    user32 = ctypes.windll.user32
    CF_DIB = 8
    GMEM_MOVEABLE = 0x0002
    user32.OpenClipboard(None)
    user32.EmptyClipboard()

    for image_path in list:
        img = Image.open(image_path)

        output = io.BytesIO()
        img.convert("RGB").save(output, "BMP")
        data = output.getvalue()[14:]
        output.close()

        global_mem = kernel32.GlobalAlloc(GMEM_MOVEABLE, len(data))
        global_data = kernel32.GlobalLock(global_mem)
        msvcrt.memcpy(ctypes.c_char_p(global_data), data, len(data))
        kernel32.GlobalUnlock(global_mem)
        user32.SetClipboardData(CF_DIB, global_mem)

    user32.CloseClipboard()
Community
  • 1
  • 1
Hisu
  • 117
  • 9

0 Answers0