Created
January 30, 2012 03:59
-
-
Save urbushey/1702408 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import win32api, sys import Image import win32clipboard from cStringIO import StringIO def send_to_clipboard(clip_type, data): win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(clip_type, data) win32clipboard.CloseClipboard() if __name__ == '__main__': # get the file and verify PIL can open it try: image = Image.open(sys.argv[1]) except IOError, e: win32api.MessageBox(0, 'Cannot open %s: %s' % (sys.argv[1], str(e)), 'Copy Image to Clipboard') output = StringIO() # convert the file try: image.convert("RGB").save(output, "BMP") except Exception, e: win32api.MessageBox(0, 'Cannot convert %s to Bitmap: %s' % (sys.argv[1], str(e)), 'Copy Image to Clipboard') data = output.getvalue()[14:] output.close() send_to_clipboard(win32clipboard.CF_DIB, data)