Clipboard.ContainsImage inconsistent with Clipboard.GetImage
See original GitHub issueIn #493 it was decided that removing metafile support from Clipboard.GetImage is by design. However Clipboard.SetImage and Clipboard.ContainsImage were never adjusted and still support metafiles, this leads to an inconsistent API.
Clipboard.SetImage(new Metafile("example.emf")); // copies the metafile to the clipboard
Clipboard.ContainsImage(); // returns true
Clipboard.GetImage(); // returns null by design, issue #493
GetImagereturning null (instead of throwing an exception) is correct, since all clipboard APIs return null if there is no compatible data available. Since #493 removes compatibility for reading metafiles this is expected behavior.ContainsImagereturningtrueif a metafile is present is a bug, it must returnfalsebecauseGetImagewill not be able to read the metafile.SetImagestill supports metafiles so we now have a write-only API which is arguably not a bug, but it may be confusing why you can write metafiles but not read them back. If you want to drop support for metafiles from SetImage as well then it should throw an exception.
Side note: I didn’t test it explicitely but I assume the DataObject APIs behave the same way as the Clipboard APIs and need the same fix.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Is Clipboard.ContainsImage() reliable or even useful?
It is more performant than calling GetImage() , therefore its worth doing even though in a small % of cases GetImage() will fail?...
Read more >Clipboard.GetImage() returns null when ...
Developer Community. For unknown reason, Clipboard. GetImage() returns null even if there is a bitmap in the clipboard.
Read more >[Solved] Clipboard and External Images
But the same image copied to the clipboard outside the app returns a null with Clipboard.GetImage() as well as false from ContainsImage().
Read more >Clipboard.ContainsImage Method (System.Windows.Forms)
Indicates whether there is data on the Clipboard that is in the Bitmap format or can be converted to that format.
Read more >Wrestling with Clipboard Images in WPF - Rick Strahl's Web Log
Getting images from the clipboard correctly in WPF - or heck in general in Windows - is hard if you need it to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’d like @JeremyKuhne and @lonitra to factor this into their research and planning for resources and clipboard moving forward. BinaryFormatter deprecation and how we decide to handle that might open up some options here.
Not at all, will create a separate PR for the
DataObjectchanges not directly related to the process crash.