Chr*_*ber 6 .net c# drawing image
我有一个EMF文件.我想把它缩小一点.
如何在.net(或使用任何工具)中执行此操作而不会出现模糊图像?
生成的已调整大小的图像将转换为另一种格式(png/jpg /无论如何),我可以处理(我认为).
我还没有在.Net(或任何语言平台)中找到一个处理emf/metafiles的明确例子.
我用GDI +查看了图形编程,但它只介绍了Metafiles.
我已经尝试了Image Magick,但你必须转换为另一种格式(我还需要做),结果很模糊(例如缩小并转换为png).
我已经尝试过Inkscape,但是你只能导入一个EMF文件而Inkscape将它倒置 并且不成比例地导入到现有的绘图中.
另外,(不要笑)我已经在Window's Paint中打开了它(为数不多的将打开emf的图像编辑软件程序之一)并调整了绘图大小,再次模糊.
更新:这是我用来调整大小的代码.
这样可行,但生成的图像模糊不清.代码只是一个通用的图像重新调整例程,不是特定于EMF的
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;
}
Run Code Online (Sandbox Code Playgroud)
资料来源:http: //www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing
我使用以下代码(类似于编辑后的代码)来重新调整emf图像的大小.它似乎并不模糊.
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);
}
Run Code Online (Sandbox Code Playgroud)