none
WPF中如何显示emf格式文件以及字间距设置 RRS feed

答案

  • 自己搞定了,不能直接使用但可以先转成bmp格式然后再用(放大一定比例后会有马赛克,毕竟是BMP格式了)

                Metafile emf = new Metafile(FileName);
                if (emf == null) return;

                System.Drawing.Graphics G;
                System.Drawing.Bitmap b = new System.Drawing.Bitmap((Int32)Width, (Int32)Height);
                G = System.Drawing.Graphics.FromImage(b);
                G.DrawImage(emf, 0, 0, (float)Width, (float)Height);
                ImageSource imgs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(b.GetHbitmap(),
                    IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
    到这里生成ImageSource了,可以用了

    2011年9月1日 8:25

全部回复

  • WPF does not support the EMF and WMF image formats. These formats are more susceptible to security vulnerabilities than other image formats, so we do not intend to support them. However, the Windows Imaging Component, which is part of WPF, is extensible. A 3rd party could write a codec for EMF or WMF that's compatible with the Windows Imaging Component. Anyone who installs the codec will be able to display the corresponding image format in any WPF application or any application built on WIC. (Like any image format, if a security vulnerability is found, the codec will be disabled until a patch is released.)

     http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7010cefa-e596-45af-b193-40206451dd90/


    2011年8月30日 12:10
  • 大致意思是WPF本身因为EMF格式的安全性问题不支持EMF格式。 由于WPF的图片处理是基于Windows Imaging Component的,所以第三方仍然可以自己编写与WIC兼容的EMF格式的codec并在WPF中使用。


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    2011年8月31日 9:29
    版主
  • 自己搞定了,不能直接使用但可以先转成bmp格式然后再用(放大一定比例后会有马赛克,毕竟是BMP格式了)

                Metafile emf = new Metafile(FileName);
                if (emf == null) return;

                System.Drawing.Graphics G;
                System.Drawing.Bitmap b = new System.Drawing.Bitmap((Int32)Width, (Int32)Height);
                G = System.Drawing.Graphics.FromImage(b);
                G.DrawImage(emf, 0, 0, (float)Width, (float)Height);
                ImageSource imgs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(b.GetHbitmap(),
                    IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
    到这里生成ImageSource了,可以用了

    2011年9月1日 8:25