.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ConvertingEMF file to WMF

7 REPLIES 7
Reply
Message 1 of 8
sivashanmugam
1190 Views, 7 Replies

ConvertingEMF file to WMF

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.
7 REPLIES 7
Message 2 of 8
Anonymous
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]
Message 3 of 8

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.
Message 4 of 8
Anonymous
in reply to: sivashanmugam

Sorry, but I did not understood what you want 😞
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.
Message 5 of 8

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.
Message 6 of 8

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.
Message 7 of 8
Anonymous
in reply to: sivashanmugam

Ok! This function translate EMF to WMF with raster image. 😞
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.
Message 8 of 8
Anonymous
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost