开发者

Convert Bitmap to Metafile (.emf)

I have a bitmap(.bmp) file and I want to convert it into metafile(.emf) format. Currently I am using this code:

        Metafile metafile;
        using (MemoryStream stream开发者_Python百科 = new MemoryStream())
        using (Graphics rtfBoxGraphics = m_ActiveTab.Controls[0].CreateGraphics())
        {
          IntPtr pDeviceContext = rtfBoxGraphics.GetHdc();

          metafile = new Metafile(stream, pDeviceContext);
          using (Graphics imageGraphics = Graphics.FromImage(metafile))
          {               
            imageGraphics.DrawImageUnscaled(bmp1, new Rectangle(0, 0,bmp1.Width, bmp1.Height));     
          }
          rtfBoxGraphics.ReleaseHdc(pDeviceContext);
        }

        // Get a handle to the metafile
        IntPtr iptrMetafileHandle = metafile.GetHenhmetafile();

        // Export metafile to an image file
        CopyEnhMetaFile(iptrMetafileHandle, @"e:\Test\test4.emf");

        // Delete the metafile from memory
        DeleteEnhMetaFile(iptrMetafileHandle);


[DllImport("gdi32.dll")]
static extern IntPtr CopyEnhMetaFile(  // Copy EMF to file
  IntPtr hemfSrc,   // Handle to EMF
  String lpszFile // File
);

[DllImport("gdi32.dll")]
static extern int DeleteEnhMetaFile(  // Delete EMF
  IntPtr hemf // Handle to EMF
);

Why is this code not work properly? Please provide me full code to convert a bitmap file to metafile(specially .emf) file. or If possible then tell me how can I save a graphics object in metafile format. Suppose I have this code

Graphics NewGraphicsObj = m_ActiveTab.Controls[0].CreateGraphics();

now I want to save this NewGraphicsObj into a metafile.

Any one help on this topic

Thanks in advance...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜