Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

TomTheTeacher
Posted

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) {
	ListBox1.Items.Clear();
	ListBox1.Items.AddRange(dataObject.GetFormats(true));
}


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.
 
Share this answer
 
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.

Regards,

TomTheTeacher
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900