.NET

Reply
Valued Contributor
sivashanmugam
Posts: 58
Registered: ‎03-05-2006
Message 1 of 8 (490 Views)

ConvertingEMF file to WMF

490 Views, 7 Replies
03-18-2006 04:17 AM
Hai,
hw to convert an emf file to wmf file using C#.NET or vb.net.

I need the emf file as the input and the corresponding wmf file as the output.

Plz Plz help,

Regards,
N. Siva shanmugam.
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 2 of 8 (490 Views)

Re: ConvertingEMF file to WMF

03-18-2006 01:13 PM in reply to: sivashanmugam
Try this code:
[code]
using System ;
using System.Drawing;
using System.Drawing.Imaging;
using Autodesk.AutoCAD.Runtime ;

[assembly: CommandClass(typeof(ConvertLIB.EMF2WMFClass))]

namespace ConvertLIB
{
public class EMF2WMFClass
{
// [CommandMethod("EMF2WMF")]
// static public void test()
// {
// Emf2Wmf("C:\\input.emf","C:\\output.wmf");
// }
//
// Convert file from EMF to WMF
//
static public void Emf2Wmf(string EMFpath, string WMFpath)
{
Image img = Image.FromFile(EMFpath);
img.Save(WMFpath,ImageFormat.Wmf);
img.Dispose();
}
}
}
[/code]
Valued Contributor
sivashanmugam
Posts: 58
Registered: ‎03-05-2006
Message 3 of 8 (490 Views)

Re: ConvertingEMF file to WMF

03-19-2006 08:11 AM in reply to: sivashanmugam
Hai,

Thanks for the reply

The code snippnet you have is creating a WMF but the appropriate object in EMF file is not created properly.

I have seen in one of the article it can be created using metafile class or plz try to give your another way of option.

Can u help in that how to create an EMF file as input to WMF file as output using metafile class

plz help
Regards
N. Siva shanmugam.
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 4 of 8 (490 Views)

Re: ConvertingEMF file to WMF

03-19-2006 08:42 AM in reply to: sivashanmugam
Sorry, but I did not understood what you want :smileysad:
In previous post you said that you have emf-file and you want to create wmf-file from it. My code do it. Describe your's problem exactly.
Valued Contributor
sivashanmugam
Posts: 58
Registered: ‎03-05-2006
Message 5 of 8 (490 Views)

Re: ConvertingEMF file to WMF

03-19-2006 09:33 PM in reply to: sivashanmugam
Hai,
The code u have give is creating a WMF file.

But the problem is that when I open that WMF in Autocad 2006 it is not opening that WMF file.

What is the problem.

Plz help,

Regards,
N. Siva shanmugam.
Valued Contributor
sivashanmugam
Posts: 58
Registered: ‎03-05-2006
Message 6 of 8 (490 Views)

Re: ConvertingEMF file to WMF

03-19-2006 09:35 PM in reply to: sivashanmugam
Hai,
The code u have given is creating an WMF file.

But when I open in Autocad 2006 the object available in the WMF file is not loading. What is the problem.

Regards,
N. Siva shanmugam.
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 7 of 8 (490 Views)

Re: ConvertingEMF file to WMF

03-20-2006 04:31 AM in reply to: sivashanmugam
Ok! This function translate EMF to WMF with raster image. :smileysad:
I attached arx-file which export command EMF2WMF and lisp function (emf2wmf "input.emf" "output.wmf") Try it. How invoke command from C# was described by Tony in this forum.
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 8 of 8 (490 Views)

Re: ConvertingEMF file to WMF

03-20-2006 12:11 PM in reply to: sivashanmugam
Another solution:
[code]
//-------------------------------------------------------------------
// This class using ConvertEmf2Wmf.dll, which must be "visible", eg.
// in AutoCAD directory, or in directory of this assembly, or ...
//-------------------------------------------------------------------

using System ;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
using Autodesk.AutoCAD.Runtime ;
using System.Runtime.InteropServices;

[assembly: CommandClass(typeof(ConvertLIB.EMF2WMFClass))]

namespace ConvertLIB
{
public class EMF2WMFClass
{
//----------------------------------------------
// Command for testing ConvertEmf2Wmf function
//----------------------------------------------
[CommandMethod("EMF2WMF")]
static public void test()
{
ConvertEmf2Wmf("C:\\input.emf","C:\\output.wmf");
}
//-----------------------------------------------
// Function for converting EMF-file to WMF-file
//-----------------------------------------------
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("ConvertEmf2Wmf.dll", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
private extern static void ConvertEmf2Wmf(string emf_path, string wmf_path);
}
}
[/code]
Source code of ConvertEmf2Wmf.dll
[code]
#include "stdafx.h"
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}

extern "C" __declspec(dllexport) void ConvertEmf2Wmf(char *sFileEmf, char *sFileWmf)
{
HDC hDc = GetDC(GetDesktopWindow()),
hDcComp = CreateCompatibleDC(hDc);
ReleaseDC(GetDesktopWindow(), hDc);
SetMapMode(hDcComp,MM_ANISOTROPIC);
HENHMETAFILE hEmf = GetEnhMetaFile(sFileEmf);
UINT uSize = GetWinMetaFileBits(hEmf, 0, NULL, MM_ANISOTROPIC, hDcComp);
BYTE *pBuffer = (BYTE *) GlobalAlloc(GPTR, uSize);
GetWinMetaFileBits(hEmf, uSize, pBuffer, MM_ANISOTROPIC, hDcComp);
HMETAFILE hWmf = SetMetaFileBitsEx(uSize, pBuffer);
PlayMetaFile(hDcComp, hWmf);
HMETAFILE hWmfNew = CopyMetaFile(hWmf, sFileWmf);
DeleteMetaFile(hWmfNew);
DeleteMetaFile(hWmf);
DeleteEnhMetaFile(hEmf);
GlobalFree(pBuffer);
DeleteDC(hDcComp);
}
[/code]
In attachment I post ConvertEmf2Wmf.dll
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.