search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

C# WMF 圖檔 轉 JPG 圖檔 – jashliao部落格

C# WMF 圖檔 轉 JPG 圖檔


資料來源:

    sample wmf file : https://example-files.online-convert.com/vector image/wmf/example.wmf [該網站有各式各樣的檔案格式範例實體提供測試下載]
    convert wmf to jpg c# : https://social.msdn.microsoft.com/Forums/vstudio/en-US/6341c2b2-ca60-45f0-9253-fdd35469d155/convert-wmf-to-jpg?forum=csharpgeneral


GITHUB: https://github.com/jash-git/CS_WMF2JPG


Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

namespace CS_WMF2JPG
{
    /*
     sample wmf file : https://example-files.online-convert.com/vector image/wmf/example.wmf
     convert wmf to jpg c# : https://social.msdn.microsoft.com/Forums/vstudio/en-US/6341c2b2-ca60-45f0-9253-fdd35469d155/convert-wmf-to-jpg?forum=csharpgeneral
     */
    class Program
    {
        static void Pause()
        {
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
        static void WMF2JPG(String StrInputFile)
        {
            String StrOutputFile = StrInputFile.Split('.')[0] + ".jpg";

            Image i = Image.FromFile(StrInputFile, true);
            Bitmap b = new Bitmap(i);

            Graphics g = Graphics.FromImage(b);
            /*
                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.
            */
            g.Clear(Color.White);

            g.DrawImage(i, 0, 0, i.Width, i.Height);
            b.Save(StrOutputFile, ImageFormat.Jpeg);

        }
        static void Main(string[] args)
        {
            WMF2JPG("example.wmf");
            Pause();
        }
    }
}


input(WMF):


output(JPG):



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦