title: Copy image to clipboard?
body: <p>First of all, the question on SO <a href="https://stackoverflow.com/questions/15243994/copy-image-to-clipboard-in-python">copy image to clipboard in python</a> leads to answer <a href="https://stackoverflow.com/questions/7050448/write-image-to-windows-clipboard-in-python-with-pil-and-win32clipboard">Write image to Windows clipboard in python with PIL and win32clipboard?</a>, which was only good for Python 2.x. -- I tried it and it didn't work. I overcame one problem: <a href="https://stackoverflow.com/questions/11914472/stringio-in-python3">StringIO and cStringIO modules are gone in Python 3.0:</a>, but bumped into another one:</p>
  
  <pre><code>TypeError: string argument expected, got 'bytes'
  </code></pre>
  
  <p>Hence, re-asking the same question again for Python 3 -- How to copy image to clipboard in Python 3? Here is the code I've got so far:</p>
  
  <pre><code>from io import StringIO
  import win32clipboard
  from PIL import Image
  
  def send_to_clipboard(clip_type, data):
      win32clipboard.OpenClipboard()
      win32clipboard.EmptyClipboard()
      win32clipboard.SetClipboardData(clip_type, data)
      win32clipboard.CloseClipboard()
  
  filepath = 'image.jpg'
  image = Image.open(filepath)
  
  output = StringIO()
  image.convert("RGB").save(output, "BMP")
  data = output.getvalue()[14:]
  output.close()
  
  send_to_clipboard(win32clipboard.CF_DIB, data)
  </code></pre>
  
  <p>Thanks</p>