473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get metafile from clipboard object

Hi

I need to retrieve a metafile image from the clipboard and render it as a
bitmap in my application. In particular, an image will be placed on the
clipboard by pasting from PowerPoint (I really do need to do this!). The
original image is a bitmap, but PowerPoint doesn't place it on the clipboard
as such. A call to GetFormats() indicates that MetafilePict and
EnhancedMetaFil e are available formats.

The following does NOT work:

Dim metaFile As System.Drawing. Imaging.Metafil e

If data.GetDataPre sent(DataFormat s.MetafilePict) Then
obj = data.GetData(Da taFormats.Metaf ilePict, True)
metaFile = CType(obj, System.Drawing. Imaging.Metafil e)
....
End If
The GetDataPresent( ) test returns true, indicating there is a MetafilePict.
The GetData returns something (it's not "Nothing") but I can't figure out
what to do with it. The CType returns "Nothing" in metaFile.

Help?

Thanks,
--George
* George Yefchak
* Phone: 408-970-0419
* Cell: 408-981-5521
* E-mail: ge****@yefchak. com
* Web: www.yefchak.com
Nov 20 '05 #1
2 8002
Hi George,

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.GetDa taObject()

If objData.GetData Present(GetType (System.Drawing .Bitmap)) Then
Dim bmp As System.Drawing. Bitmap =
CType(objData.G etData(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.

Craig,
VB .Net Team
--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).

--------------------
From: "George Yefchak" <ge****@yefchak .com>
Subject: Get metafile from clipboard object
Date: Tue, 27 Jan 2004 11:30:03 -0800
Lines: 35
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Organization : Agilent Laboratories, Palo Alto, CA
Message-ID: <10************ ***@emperor.lab s.agilent.com>
Cache-Post-Path: em************* *************** **@hploboe.labs .agilent.com
X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/)
Cache-Post-Path: cs************* *************** **@emperor.labs .agilent.com
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: cswrelay.cos.ag ilent.com 192.6.143.83
Path: cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!TK2 MSFTNGP08.phx.g bl!TK2MSFTNGP10 .
phx.gblXref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:176589
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

Hi

I need to retrieve a metafile image from the clipboard and render it as a
bitmap in my application. In particular, an image will be placed on the
clipboard by pasting from PowerPoint (I really do need to do this!). The
original image is a bitmap, but PowerPoint doesn't place it on the clipboardas such. A call to GetFormats() indicates that MetafilePict and
EnhancedMetaFi le are available formats.

The following does NOT work:

Dim metaFile As System.Drawing. Imaging.Metafil e

If data.GetDataPre sent(DataFormat s.MetafilePict) Then
obj = data.GetData(Da taFormats.Metaf ilePict, True)
metaFile = CType(obj, System.Drawing. Imaging.Metafil e)
...
End If
The GetDataPresent( ) test returns true, indicating there is a MetafilePict.
The GetData returns something (it's not "Nothing") but I can't figure out
what to do with it. The CType returns "Nothing" in metaFile.

Help?

Thanks,
--George
* George Yefchak
* Phone: 408-970-0419
* Cell: 408-981-5521
* E-mail: ge****@yefchak. com
* Web: www.yefchak.com



Nov 20 '05 #2
Hi George,

I was able to get more information on your question. First of all, there
seems to be an issue getting apps in general and .NET apps to be able to
see each others metafiles when saved to the clipboard. Here's a KB article
that examines one half of this issue:
http://support.microsoft.com/?id=323530

There is a way to do what you want, but you have to use WinAPIs. Here's an
example (which you may want to refine).

1. Add a class named ClipboardAPI and add the following code to the class

Imports System.Runtime. InteropServices

Public Class ClipboardAPI

<DllImport("use r32.dll", EntryPoint:="Op enClipboard", _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function OpenClipboard(B yVal hWnd As IntPtr) As Boolean
End Function

<DllImport("use r32.dll", EntryPoint:="Em ptyClipboard", _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function EmptyClipboard( ) As Boolean
End Function

<DllImport("use r32.dll", EntryPoint:="Se tClipboardData" , _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function SetClipboardDat a(ByVal uFormat As Integer, ByVal
hWnd As IntPtr) As IntPtr
End Function

<DllImport("use r32.dll", EntryPoint:="Cl oseClipboard", _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function CloseClipboard( ) As Boolean
End Function

<DllImport("use r32.dll", EntryPoint:="Ge tClipboardData" , _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function GetClipboardDat a(ByVal uFormat As Integer) As
IntPtr
End Function

<DllImport("use r32.dll", EntryPoint:="Is ClipboardFormat Available", _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function IsClipboardForm atAvailable(ByV al uFormat As
Integer) As Short
End Function
End Class

2. Add the following to your button click event

Const CF_ENHMETAFILE As Integer = 14

Dim henmetafile As IntPtr
Dim metaFile As System.Drawing. Imaging.Metafil e

If ClipboardAPI.Op enClipboard(Me. Handle) Then
If ClipboardAPI.Is ClipboardFormat Available(CF_EN HMETAFILE) <> 0
Then
henmetafile = ClipboardAPI.Ge tClipboardData( CF_ENHMETAFILE)
metaFile = New Metafile(henmet afile, True)
ClipboardAPI.Cl oseClipboard()
End If
End If

Hope this helps,
Craig VB.NET Team
--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).

--------------------
From: "George Yefchak" <ge****@yefchak .com>
Subject: Get metafile from clipboard object
Date: Tue, 27 Jan 2004 11:30:03 -0800
Lines: 35
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Organization : Agilent Laboratories, Palo Alto, CA
Message-ID: <10************ ***@emperor.lab s.agilent.com>
Cache-Post-Path: em************* *************** **@hploboe.labs .agilent.com
X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/)
Cache-Post-Path: cs************* *************** **@emperor.labs .agilent.com
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: cswrelay.cos.ag ilent.com 192.6.143.83
Path: cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!TK2 MSFTNGP08.phx.g bl!TK2MSFTNGP10 .
phx.gblXref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:176589
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

Hi

I need to retrieve a metafile image from the clipboard and render it as a
bitmap in my application. In particular, an image will be placed on the
clipboard by pasting from PowerPoint (I really do need to do this!). The
original image is a bitmap, but PowerPoint doesn't place it on the clipboardas such. A call to GetFormats() indicates that MetafilePict and
EnhancedMetaFi le are available formats.

The following does NOT work:

Dim metaFile As System.Drawing. Imaging.Metafil e

If data.GetDataPre sent(DataFormat s.MetafilePict) Then
obj = data.GetData(Da taFormats.Metaf ilePict, True)
metaFile = CType(obj, System.Drawing. Imaging.Metafil e)
...
End If
The GetDataPresent( ) test returns true, indicating there is a MetafilePict.
The GetData returns something (it's not "Nothing") but I can't figure out
what to do with it. The CType returns "Nothing" in metaFile.

Help?

Thanks,
--George
* George Yefchak
* Phone: 408-970-0419
* Cell: 408-981-5521
* E-mail: ge****@yefchak. com
* Web: www.yefchak.com

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1694
by: fowlertrainer | last post by:
Hi ! My problem is that: I have a program that copy pictures from Notes NSF file. The format is METAFILE or METAFILEPICT. I can save these pictures with this code: import win32api import win32con import win32gui
2
4803
by: Julian Ziersch | last post by:
This code causes a severe memory leak - the critical part is the call to GetHenhmetafile(). System.Drawing.Imaging.Metafile lImage = new System.Drawing.Imaging.Metafile("C:\\meta0.emf"); IntPtr h = lImage.GetHenhmetafile(); lImage.Dispose(); lImage.GetLifetimeService(); lImage = null;
3
417
by: Richard Skopal | last post by:
In .NET Windows forms I can create a metafile using this code: Graphics grph = aControl.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(aImgFilePath, ipHDC, EmfType.EmfOnly); grph.ReleaseHdc(ipHDC); grph.Dispose(); grph = Graphics.FromImage(mf); grph.DrawRectangle(aPen, 10, 10, 100, 120); grph.Dispose();
0
1619
by: Ben Leino | last post by:
Hi out there, I have a quite huge problem that I can't solve after huge "googeling and msdnning". Ich have a litte VB.NET class that opens a PowerPoint Presentation (COM) and wants to extract an image of one of its shapes. But i am not able to convert this Ehanced Metafile from Clipboard to real file on harddisk. For example jpg or bmp. Who can help? Code looks like this:
1
3090
by: B. Cline | last post by:
Hi, I need to write a conversion routine to split pictures out of about 10000 word documents. (Actually the text is converted to RTF, the pictures should be converted to jpg). I thought I could simply save the word doc as rtf and strip the picture. That works. The problem is getting the picture to save correctly. I can use word to determine which pictures are in the original document and can get them to the clipboard. I can't seem to...
0
1792
by: weiruic | last post by:
I am trying to create a metafile (.emf) on the harddisk, write graphics from a graphics object to it, and then save it. I can do this successfully except I cannot set the horizontal and vertical resolution as those properties of my metafile object are read only and are in fact null until the graphics object is disposed of and the file is saved. When I examine the saved file's properties in Windows Explorer, it has 81 dpi horizontal and...
2
1724
by: NickP | last post by:
Hi there, I am obtaining a meta file from the clipboard via the following code Dim CF_ENHMETAFILE As Integer = 14 Dim cMFeImage As Imaging.Metafile Dim pIPrClipboard As IntPtr = OpenClipboard(Me.Handle)
2
2546
by: Alexander Gorbylev | last post by:
Hi! Let the size of vector is e.g. 3.5". I render the same vector on a printer & a screen on the same procedure: printDoc_BeginPrint(object sender, PrintEventArgs e) { .... vector.Width * g.DpiX ....
1
3631
by: bern11 | last post by:
I can get bitmaps from the clipboard, but how do I get Metafiles? The specific instance I am testing is copying a piece of Word clip-art into the clipboard and trying to read it in an application. It appears as a metafile type but isn't recognized as an image. Given: DataObject copyObject; copyObject = (DataObject)Clipboard.GetDataObject(); string types = copyObject.GetFormats();
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.