질문하기질문하기
 

답변됨Convert WMF to JPG

  • 2006년 8월 21일 월요일 오후 1:34kennethkryger 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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?

답변

  • 2006년 8월 21일 월요일 오후 7:37Brendan Grant중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

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

모든 응답

  • 2006년 8월 21일 월요일 오후 1:46Brendan Grant중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

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

  • 2006년 8월 21일 월요일 오후 6:31kennethkryger 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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?

  • 2006년 8월 21일 월요일 오후 7:37Brendan Grant중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

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

  • 2006년 8월 22일 화요일 오전 8:11kennethkryger 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Perfect!

    Thank you very much for your help!