An unclear converted image. wmf to png

安稳与你 提交于 2019-12-05 18:29:52

The .wmf file has extremely large values for DpiX/Y. You'll need to rescale the image to make it a better fit with the resolution of your monitor. This code produced a decent looking version of the metafile. You may want to tweak the scaling to fit your need or rescale the bitmap afterwards:

        using (Metafile img = new Metafile(@"c:\temp\test.wmf")) {
            MetafileHeader header = img.GetMetafileHeader();
            float scale = header.DpiX / 96f;
            using (Bitmap bitmap = new Bitmap((int)(scale * img.Width / header.DpiX * 100), (int)(scale * img.Height / header.DpiY * 100))) {
                using (Graphics g = Graphics.FromImage(bitmap)) {
                    g.Clear(Color.White);
                    g.ScaleTransform(scale, scale);
                    g.DrawImage(img, 0, 0);
                }
                bitmap.Save(@"c:\temp\test.png", ImageFormat.Png);
            }
        }

Finally, I got an IDEA!!

That is to use Inkspace.
As you all know, Inkscape is an Vector Graphics Editor.
Today, I found out that INKSCAPE HAS COMMAND LINE OPTIONS!! http://goo.gl/Moksf .
So, what I should do is to call incape.exe with some options, such like:

Process.Start("inkscape.exe -f {wmf_filename} -e {png_filename_to_be_made}");

Here is converted png file : http://yfrog.com/gyu40ap
very clear png image. that is what I wanted to!

Thank you!

EMF vectors can be very weird when converting to a PNG (especially when small formats are used). I ended up blowing it up 4x and than converting it to the size I want. The results are better when using this strategy.


Source: https://keestalkstech.com/2016/06/rasterizing-emf-files-with-net-c/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!