locked
Metafile to Bitmap RRS feed

  • Question


  • I need to give selected text from Visio (it's give me metafile) and convert it to bitmap image. I use such code:

    using (Metafile winMetafile = (System.Drawing.Imaging.Metafile)Image.FromFile(pathToMetaFile, true))
            {
                var header = winMetafile.GetMetafileHeader();
                var kw = header.Bounds.Width / header.DpiX;
                var kh = header.Bounds.Height / header.DpiY;
    
                var width = kw * Resolutions.ScreenDpi;
                var height = kh * Resolutions.ScreenDpi;
    
                using (var bitmap = new Bitmap((int)width, (int)height, winMetafile.PixelFormat))
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.Clear(System.Drawing.Color.White);g.DrawImage(winMetafile, 0, 0, width, height);
                        this.ImagePreviewSource = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        this.ImageWidth = this.ImagePreviewSource.Width;
                        this.ImageHeight = this.ImagePreviewSource.Height;
                    }
                }
            }

    It's work fine in old versions of Visio, like 2010, 2008 etc. But when I try it in Visio 2015 - it's work, but with very low quality. Images in bitmap looks like "stair-stepping". But when I open metafile - it's look good. I guess that problem links to alpha channel or opacity, but I don't know how to fix it. Could anybody help me.

    Update 1

    I wrote wrong version of Visio. I mean that I use Visio 2013 (not 2015).



    • Edited by rubkaarchi Tuesday, January 13, 2015 7:47 AM
    Monday, January 12, 2015 12:23 PM

All replies