如何调整(收缩)的EMF(图元文件)在.net中? [英] How do I resize (shrink) an EMF (Metafile) in .Net?

查看:245
本文介绍了如何调整(收缩)的EMF(图元文件)在.net中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EMF文件。我想调整它的大小更小。

I have an EMF file. I want to resize it smaller.

我如何做到这一点的。NET(或任何工具)的没有得到一个模糊的图片

How do I do this in .net (or with any tool) without getting a blurry image?

由此产生的调整后的图像转换为另一种格式(PNG / JPG /其他),我可以搞定(我认为)。

The resulting resized image will be converted to another format (png/jpg/whatever), I can handle that (I think).

我还没有发现与EMF /图元文件处理在.net一个明显的例子(或任何语言平台的事情)。

I haven't found a clear example in .Net (or any language platform for the matter) that deals with emf/metafiles.

我+ 的期待与GDI中的图形编程,但只介绍图元文件。

I've looked in the Graphics Programming with GDI+ but it only introduces Metafiles.

我已经试过难懂,但你必须转换为另一种格式(我需要做的工作),结果是模糊(缩水并转换为PNG例如,当)。

I've tried Image Magick but you have to convert to another format (which I need to do anyway) and the result is blurry (when shrunk and converted to png for example).

我已经试过Inkscape的,但你只能导入EMF文件和Inkscape中导入它的倒挂的和不成比例到现有的绘图。

I've tried Inkscape, but you can only import an EMF file and Inkscape imports it upside down and out of proportion into an existing drawing.

另外,(不要笑)我已经打开了它在Windows的画图(为数不多的图像编辑软件程序,将打开EMF的一个),并调整大小的图纸,这又是模糊的。

Also, (don't laugh) I've opened it up in Window's Paint (one of the few image editing software programs that will open emf's) and resized the drawing, again it's blurry.

更新: 这里是code我使用来调整。

Update: Here is the code I'm using to resize.

这工作,但由此产生的图像模糊。在code是只是一个普通的图像大小调整程序,没有具体到EMF的

This works, but the resulting image is blurry. The code is just a generic image re-sizing routine, not specific to EMF's

private static Image resizeImage(Image imgToResize, Size size)
{
    int sourceWidth = imgToResize.Width;
    int sourceHeight = imgToResize.Height;

    float nPercent = 0;
    float nPercentW = 0;
    float nPercentH = 0;

    nPercentW = ((float)size.Width / (float)sourceWidth);
    nPercentH = ((float)size.Height / (float)sourceHeight);

    if (nPercentH < nPercentW)
        nPercent = nPercentH;
    else
        nPercent = nPercentW;

    int destWidth = (int)(sourceWidth * nPercent);
    int destHeight = (int)(sourceHeight * nPercent);

    Bitmap b = new Bitmap(destWidth, destHeight);
    Graphics g = Graphics.FromImage((Image)b);
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

    g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
    g.Dispose();

    return (Image)b;
}

来源: <一href="http://www.switchonthe$c$c.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing" rel="nofollow">http://www.switchonthe$c$c.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing

推荐答案

即时通讯使用以下code(类似于你在编辑后有)用于调整大小的EMF图像。它似乎并没有得到模糊。

Im using the following code (similar to what you have after the edit) for re-sizing an emf image. It does not seem to get blurry.

var size = new Size(1000, 1000);

using(var source = new Metafile("c:\\temp\\Month_Calendar.emf"))
using(var target = new Bitmap(size.Width, size.Height))
using(var g = Graphics.FromImage(target))
{
    g.DrawImage(source, 0, 0, size.Width, size.Height);
    target.Save("c:\\temp\\Month_Calendar.png", ImageFormat.Png);
}

这篇关于如何调整(收缩)的EMF(图元文件)在.net中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆