Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# clipboard WinForm
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 29-Jun-11 17:24pm
Rate this: bad
good
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) {
	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.
  Permalink  
Rate this: bad
good
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.
 
Regards,
 
TomTheTeacher
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 Sergey Alexandrovich Kryukov 170
4 PIEBALDconsult 160
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 6 Jul 2011
Copyright © CodeProject, 1999-2014
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