enrique_mp
asked on
Convert a MetafilePict recovered from Clipboard to a System.Drawing.Image
I need to recover an imagen that y paste from Photoshop for asign it to a PictureBox.Image.
The problem that I have is that the function Clipboard.GetDataObject(). GetFormats () returns that the clipboard's data is in DataFormats.MetafilePict format and only in this format, don't support any conversion.
I tried to recover the image with this code:
if ( Clipboard.GetDataObject(). GetDataPre sent(DataF ormats.Met afilePict ) )
object o= Clipboard.GetDataObject(). GetData(Da taFormats. MetafilePi ct);
the condition is evaluated to true but the object o is assigned to null.
Anybody can help me.
Sorry for my english.
The problem that I have is that the function Clipboard.GetDataObject().
I tried to recover the image with this code:
if ( Clipboard.GetDataObject().
object o= Clipboard.GetDataObject().
the condition is evaluated to true but the object o is assigned to null.
Anybody can help me.
Sorry for my english.
try this..example code
// if you have any imageobject its ok. but make sure types are compatible which highly matters
Bitmap imageObject = (Bitmap)Image.FromFile(@"C :\Document s and Settings\Administrator\My Documents\My Pictures\man2.gif");
Clipboard.SetDataObject(im ageObject, false); // it won't remain on clipboard after application exists
IDataObject iData = Clipboard.GetDataObject(); // get the interface object
bool bDataPresent = iData.GetDataPresent(DataF ormats.Bit map); // check whether data is present
// following is just for reference
System.Drawing.Imaging.Bit mapData meta = (System.Drawing.Imaging.Bi tmapData)i Data.GetDa ta(DataFor mats.Metaf ilePict);
// you can use meta on Picture or any other objects , just for reference here.
if ( bDataPresent )
richTextBox1.Paste(DataFor mats.GetFo rmat(DataF ormats.Bit map));
R.K
// if you have any imageobject its ok. but make sure types are compatible which highly matters
Bitmap imageObject = (Bitmap)Image.FromFile(@"C
Clipboard.SetDataObject(im
IDataObject iData = Clipboard.GetDataObject();
bool bDataPresent = iData.GetDataPresent(DataF
// following is just for reference
System.Drawing.Imaging.Bit
// you can use meta on Picture or any other objects , just for reference here.
if ( bDataPresent )
richTextBox1.Paste(DataFor
R.K
You may want to try using the type rather than the data format name. I'm
not sure why, but this seemed to work more reliably for me than using the
formats. The following works when I copy a picture from PowerPoint
Dim objData As DataObject = Clipboard.GetDataObject()
If objData.GetDataPresent(Get Type(Syste m.Drawing. Bitmap)) Then
Dim bmp As System.Drawing.Bitmap =
CType(objData.GetData(GetT ype(System .Drawing.B itmap)),
System.Drawing.Bitmap)
End If
I'll have to do a little research to find out the prescribed way to convert
the MemoryStream from the clipboard to a MetaFile.
best of luck..
R.K
not sure why, but this seemed to work more reliably for me than using the
formats. The following works when I copy a picture from PowerPoint
Dim objData As DataObject = Clipboard.GetDataObject()
If objData.GetDataPresent(Get
Dim bmp As System.Drawing.Bitmap =
CType(objData.GetData(GetT
System.Drawing.Bitmap)
End If
I'll have to do a little research to find out the prescribed way to convert
the MemoryStream from the clipboard to a MetaFile.
best of luck..
R.K
ASKER
Thanks for all comments. My problem was the size of the image. The size of the image that I was copy was too big and it sames that the clipboard don't store these datas correctly.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if( Clipboard.GetDataObject().
{
object o = null;
o = Clipboard.GetDataObject().
pictureBox1.Image = (Image)o;
}