代码如下:
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); } }
评论回复