1

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 = 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...

G5W
  • 36,531
  • 10
  • 47
  • 80
Shashi Jaiswal
  • 71
  • 1
  • 3
  • 10
  • 2
    You'll want to say why your code doesn't work properly -- just saying "this code is not work properly" doesn't help anyone... – Jeremy McGee Apr 28 '11 at 09:15
  • Also, see here: http://stackoverflow.com/questions/152729/gdi-c-how-to-save-an-image-as-emf – Jeremy McGee Apr 28 '11 at 09:16
  • 1
    Nothing turns me off answering a question like requests for "full code". Nobody wants to write your program for you for free. – user229044 Apr 28 '11 at 17:10

0 Answers0