极品分享

C# 将wmf转为png文件

代码如下:

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


2020-07-23 0 /
NET学习
/
标签: 

评论回复

回到顶部