none
Convert WMF to JPG RRS feed

  • Question

  • Is there anyone that can point me in the right direction?
    I want to be able to convert some wmf-files to jpg using .net (C# or VB - doesn't matter).

    Where should I start?

    Monday, August 21, 2006 1:34 PM

Answers

  • If I recall correctly, WMF files do not store a background color which causes them to be transparent and when you convert it as we did previously, the color ends up being no color at all (ie black).

    In order to fix that we need to do a little more, namely create a new image, set it's background color and then paint the WMF file on top of it.

                Image i = Image.FromFile("SomeFile.wmf", true);

               

                Bitmap b = new Bitmap(i);

               

                Graphics g = Graphics.FromImage(b);

               

                g.Clear(Color.White);

               

                g.DrawImage(i, 0, 0, i.Width, i.Height);

               

                b.Save("C:\OutputFile.jpg", ImageFormat.Jpeg);

    Monday, August 21, 2006 7:37 PM
    Moderator

All replies

  • The .NET Framework supports a number of image formats including WMF which means its simply a matter of loading the image and then resaving it ala:

             using System.Drawing;
             using System.Drawing.Imaging;

             ...

             Image i = Image.FromFile("InputFile.wmf");
             i.Save("DestinationFile.jpg", ImageFormat.Jpeg);

    Monday, August 21, 2006 1:46 PM
    Moderator
  • Wow - that's pretty easy!

    Unfortunately, if the wmf-file has a white surrounding area, it becomes black after the convertion to jpg?
    Any suggestions?

    Monday, August 21, 2006 6:31 PM
  • If I recall correctly, WMF files do not store a background color which causes them to be transparent and when you convert it as we did previously, the color ends up being no color at all (ie black).

    In order to fix that we need to do a little more, namely create a new image, set it's background color and then paint the WMF file on top of it.

                Image i = Image.FromFile("SomeFile.wmf", true);

               

                Bitmap b = new Bitmap(i);

               

                Graphics g = Graphics.FromImage(b);

               

                g.Clear(Color.White);

               

                g.DrawImage(i, 0, 0, i.Width, i.Height);

               

                b.Save("C:\OutputFile.jpg", ImageFormat.Jpeg);

    Monday, August 21, 2006 7:37 PM
    Moderator
  • Perfect!

    Thank you very much for your help!

    Tuesday, August 22, 2006 8:11 AM
  • Hi Brendan (et al), I guess the above code must be .net talk?   Do you know what the VB macro code would be to do the same?     Thanks.   kb
    Friday, October 15, 2010 7:29 PM
  • I guess you have to post to the macro's host's forum. The availability of APIs varies from host to host.

    Office programming forums can be found at http://social.msdn.microsoft.com/Forums/en/category/officedev



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Friday, October 15, 2010 11:16 PM
  • It worked...

    Thank..


    Thursday, February 5, 2015 10:09 AM