Click here to Skip to main content
13,091,145 members (51,202 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am having an unexpected challenge. I am trying to copy an image from an external source (i.e. Explorer/MSPaint/IE) into a vs2010 C# app Win Form image control. I would assume this is not an uncommon feature. If I copy the image onto the clipboard from the C# app I have no issues accessing it. But the same image copied to the clipboard outside the app returns a null with Clipboard.GetImage() as well as false from ContainsImage(). Yet text works. Everything I read says it is not a security issue. Everything I do points that way. Size and format is not an issue.

MSDB and Google have been of little help. None of the sample code I can find works. I am running Win7/64 4GB RAM.

I would sure appreciate leads

Posted 29-Jun-11 16:24pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The biggest cause of this that I've found is the coder expecting there to be an image on the clipboard only to find, with further digging, a filepath instead.

You can build a tool really quick to see what data formats are on the clipboard. Just create a Windows Forms app with a Button and a ListBox on it and drop the following code in the Button Click event handler:
IDataObject dataObject = Clipboard.GetDataObject;
if (dataObject != null) {

The true in the GetFormats() call will list not only the data formats that are available for the object on the clipboard but also the formats that the data can be automatically converted to.

For an image, you'd normally look for DeviceIndependantBitmap.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

As it turns out, when you copy an image to the clipboard, be it in Explorer, off a Web page, etc., you are not copying the image itself but rather the path to the image. It never places an image on the clipboard. I am surprized there is not much nore written on this. Once I looked for the string path it worked fine.



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 6 Jul 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100