English 中文(简体)
Draw emf antialiased
原标题:

Is there a way to draw an emf metafile (exported form a drawing tool) with antialiasing enabled? The tools I tried are not capable of exporting emf files antaliased so I wondered if I can turn it back on manually when drawing the emf in the OnPaint override of my Controls.

If anyone can confirm that is technically possible to generate antialiased emf files, another solution would be to use a drawing tool that can export to antialiased emf or have a 3rd party converter do this later. If anyone knowns such a tool, please let me know.

EDIT: When looking at the emf instructions it doesn t seem that emf itself can actually store the information whether it is to be rendered antialiased or not. At least I couldn t find anything. It is more likely that the antialiasing is done by the playback engine. For example when I open an emf in Word 2007 it is rendered antialiased. But not when I draw it with GDI+ "playback engine" (Graphics.DrawImage(...)). or when I view it the standard windows image viewer. This makes me believe that some tools actually have their own emf playback engine. So maybe there is free .NET library (preferably with source code) that give me an object model of the emf instructions stored in the parsed emf file so I can play it back myself instead of using Graphics.DrawImage(...)?

最佳回答

We had a similar issue in a DirectX project. Upscaling and downscaling works to a certain degree, but it s faking it. If it s something you need to do over and over, you could perhaps parse the records of the WMF and draw them with GDI+ antialiased.

The following threads back this up (but they re from 2005 so things might have changed):

http://www.dotnet247.com/247reference/msgs/28/144605.aspx

http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-sdk/1127/Graphics-DrawImage-metafile-no-antialiasing

[Edit:]

These three programs might do the job for you: I m assuming you re ok with doing it by hand:

http://emf-to-vector-converter-command-line-ser.smartcode.com/info.html

http://www.verypdf.com/pdf-editor/index.html

http://www.ivanview.com/converter/emf-batch-converter.html

[Edit II:]

Well, here s a program that will let you inspect an EMF in various ways:

http://download.cnet.com/windows/3055-2383_4-10558240.html?tag=pdl-redir

...and here s a freeware library that will let you parse 122 of the EMF commands and output them in GDI+. That should probably do the trick:

http://www.codeproject.com/KB/GDI-plus/emfexplorer.aspx?msg=2359423

...oh, and notice also comment #3 on the codeproject page. Looks like someone have banged their heads against the wall before. Hope this solves your problem.

问题回答

EMF is using GDI commands, not GDI+, so it has no notion of antialiasing. I suspect that when you ask GDI+ to render the file, it sends it to GDI and just copies the resulting bitmap.

Duplicating this in code would be the same as reimplementing GDI, so it s not terribly feasible. Not impossible, just a larger job than the benefit would justify. If there is an open source utility that can open EMF files outside of Windows, you might look into the source code.

My guess is that Word is using the downsampling trick.

EMF file is a list of GDI commands. So it won t be anti-aliaised, even if under GDI+, you put a SmoothingMode() call before the drawing. You ll have to enumerate the GDI commands, then translate it into GDI+ commands.

Under Vista/Seven, you can use GDI+ 1.1 function named GdipConvertToEmfPlus/ConvertToEmfPlus. If you want your program to work with XP, you should write your own enumeration, then conversion to GDI+ commands.

The GDI enumeration then conversion to GDI+ is possible has been done by emfexplorer, but I ve written some code perhaps more easy to follow, even if it s written in Delphi.

I m putting this answer just now (I m late), because I spent a lot of time finding out a solution using ConvertToEmfPlus, and writing some tuned open source code in case this method is not available.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签