3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
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提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦