Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert a MetafilePict recovered from Clipboard to a System.Drawing.Image

Posted on 2004-04-26
6
Medium Priority
?
2,219 Views
Last Modified: 2012-05-04
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().GetDataPresent(DataFormats.MetafilePict ) )
      object o= Clipboard.GetDataObject().GetData(DataFormats.MetafilePict);            

the condition is evaluated to true but the object o is assigned to null.


Anybody can help me.

Sorry for my english.

0
Comment
Question by:enrique_mp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 4

Expert Comment

by:caner_elci
ID: 10920443
I tried the following code with Photoshop and it worked well:

if( Clipboard.GetDataObject().GetDataPresent( DataFormats.Bitmap ) )
{
      object o = null;
      o = Clipboard.GetDataObject().GetData( DataFormats.Bitmap );
      pictureBox1.Image = (Image)o;
}
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10925899
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:\Documents and Settings\Administrator\My Documents\My Pictures\man2.gif");

Clipboard.SetDataObject(imageObject,false); // it won't remain on clipboard after application exists
IDataObject iData = Clipboard.GetDataObject(); // get the interface object
bool bDataPresent = iData.GetDataPresent(DataFormats.Bitmap); // check whether data is present

// following is just for reference
System.Drawing.Imaging.BitmapData meta = (System.Drawing.Imaging.BitmapData)iData.GetData(DataFormats.MetafilePict);
// you can use meta on Picture or any other objects , just for reference here.

if ( bDataPresent )
richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Bitmap));

R.K
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10925911
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(GetType(System.Drawing.Bitmap)) Then
Dim bmp As System.Drawing.Bitmap =
CType(objData.GetData(GetType(System.Drawing.Bitmap)),
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
0
 

Author Comment

by:enrique_mp
ID: 10926491
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
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 11757146
PAQed, with points refunded (500)
ee_ai_construct - CS Mod
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question