title: How do I correctly get an Image from the Clipboard in JavaFX; What is the difference between applications that struggle and those that don't?
body: <h1>The Problem</h1>
  
  <p>JavaFX's default way of getting an image from the Windows clipboard, </p>
  
  <pre><code>Clipboard.getSystemClipboard().getImage();
  </code></pre>
  
  <p>, appears to be broken.</p>
  
  <p>Something seems to go wrong with the transparency of the image. Set on a black background, the image appears fine, but set on a white background, nothing shows at all.</p>
  
  <p><a href="https://i.stack.imgur.com/TgszF.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TgszF.gif" alt="Showing the JavaFX image transparency issue by changing the background of the application from dark to light."></a></p>
  
  <p>You can test the clipboard using <a href="https://gist.github.com/TurekBot/f639f327747e7f76639a806333756d30" rel="nofollow noreferrer">this Minimal, Complete, Verifiable example</a>.</p>
  
  <p>Environment: Windows 7, Java 8 update 202</p>
  
  <h1>What I Know</h1>
  
  <p>Below, I'll describe the things I already know.</p>
  
  <h2>There are Other People who Have Asked Similar Questions:</h2>
  
  <ul>
  <li><a href="https://stackoverflow.com/q/48932575/5432315">Getting Image from Clipboard Awt vs FX</a> </li>
  <li><a href="https://stackoverflow.com/q/34642602/5432315">Image from clipboard not correctly displayed in JavaFX 8 application</a></li>
  </ul>
  
  <p>Yet, no one has gotten at the heart of the problem or received an answer.</p>
  
  <h2>No Official Bug</h2>
  
  <p>I can't seem to find a bug regarding this issue in the <a href="https://bugs.java.com/bugdatabase/" rel="nofollow noreferrer">Java Bug Database</a>.</p>
  
  <h2>No Problem for AWT</h2>
  
  <p>This problem with images doesn't occur on the AWT clipboard, but I want a solution that uses the <em>JavaFX clipboard</em>.</p>
  
  <p><a href="https://i.stack.imgur.com/nzj9C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nzj9C.png" alt="On the right is the image from AWT&#39;s clipboard, on the left is the same image from JavaFX&#39;s clipboard."></a></p>
  
  <h2>The Clipboard Contains Multiple Formats</h2>
  
  <p>I know that the Windows clipboard contains multiple versions of the same thing, just in different formats. This is easy to see using <a href="https://www.nirsoft.net/utils/inside_clipboard.html" rel="nofollow noreferrer">InsideClipboard</a> or <a href="http://www.freeclipboardviewer.com/" rel="nofollow noreferrer">Free Clipboard Viewer</a>.</p>
  
  <p><a href="https://i.stack.imgur.com/utZhE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/utZhE.png" alt="A screenshot of InsideClipboard, showing the CF_DIB format."></a></p>
  
  <p>The JavaFX Clipboard recognizes certain formats; sometimes it has different names for them. <code>application/x-java-rawimage</code> is what Java considers an image; in code you refer to this as <code>DataFormat.IMAGE</code>.</p>
  
  <p>I suspect that the <code>DIB</code> clipboard format in Windows matches up with Java's <code>application/x-java-rawimage</code>, but can't find proof of that in the source code. </p>
  
  <h2>The Problem is Wide-Spread</h2>
  
  <h3>Problem Applications</h3>
  
  <p>JavaFX seems to have this same transparency problem with various applications that copy an image to the clipboard:</p>
  
  <ul>
  <li>Adobe Reader (from <a href="https://drive.google.com/file/d/1waZRrQM6VTN1YzaVSHkxDIzV456Jqi0y/view?usp=sharing" rel="nofollow noreferrer">a PDF with images</a>)</li>
  <li><a href="https://www.foxitsoftware.com/pdf-reader/" rel="nofollow noreferrer">Foxit Reader</a> (from <a href="https://drive.google.com/file/d/1waZRrQM6VTN1YzaVSHkxDIzV456Jqi0y/view?usp=sharing" rel="nofollow noreferrer">a PDF with images</a>)</li>
  <li>Microsoft Word 365 (from <a href="https://drive.google.com/file/d/1s3anuuIXZ4NcJGAbpYakwgqH_YAGPo9x/view?usp=sharing" rel="nofollow noreferrer">a <code>.docx</code> file with images</a>)</li>
  <li>Windows 7's Paint (<code>.png</code>, <code>.jpg</code>, <code>.gif</code>, <code>.bmp</code>)</li>
  <li><a href="https://getgreenshot.org/" rel="nofollow noreferrer">Greenshot</a> (which is an enhanced screenshot utility)</li>
  <li>Firefox 65.0.2 (copying the <a href="https://www.google.com/" rel="nofollow noreferrer">Google.com</a> logo)</li>
  </ul>
  
  <h3>Applications Without The Issue</h3>
  
  <p>I've also found some applications that copy an image to the clipboard and JavaFX can pull it out using the default method no problem:</p>
  
  <ul>
  <li><a href="https://www.getpaint.net/" rel="nofollow noreferrer">Paint.net</a></li>
  <li>The <kbd>PrtScn</kbd> button</li>
  <li>The Windows Snipping Tool</li>
  <li>Google Chrome 72.0.3626.121 (copying the <a href="https://www.google.com/" rel="nofollow noreferrer">Google.com</a> logo)</li>
  </ul>
  
  <h1>Answering The Question</h1>
  
  <p>An adequate answer should </p>
  
  <ul>
  <li>explain <em>simply</em>, <em>specifically</em>, and <em>with examples</em> why the problem occurs with some applications, but not others, and</li>
  <li>figure out where things go wrong in the JDK implementation and show specifically how to fix said implementation for the majority of the problem applications without breaking it for the applications that already work.
  
  <ul>
  <li>If it's not feasible to change the JDK's implementation, an adequate answer will provide a <a href="https://stackoverflow.com/help/mcve">Minimal, Complete, and Verifiable example</a> showing JavaFX code that produces an <code>Image</code> from the JavaFX clipboard when an image is copied from Adobe Reader.</li>
  </ul></li>
  </ul>
  
  <p>If you can't help, but think this is a <a href="https://stackoverflow.com/help/why-vote">well researched</a> question, consider voting, or sharing it with a friend. </p>