Stellen Sie eine FrageStellen Sie eine Frage
 

BeantwortetConvert WMF to JPG

Antworten

  • Montag, 21. August 2006 19:37Brendan GrantModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet

    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);

Alle Antworten

  • Montag, 21. August 2006 13:46Brendan GrantModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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);

  • Montag, 21. August 2006 18:31kennethkryger TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    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?

  • Montag, 21. August 2006 19:37Brendan GrantModeratorTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet

    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);

  • Dienstag, 22. August 2006 08:11kennethkryger TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    Perfect!

    Thank you very much for your help!