Fk:假如我有一个psd源文件,我想把它转换成jpg、png、gif格式怎么办呢,往下走
Nt:可对方法进行拓展完善
添加引用:MagickNet 文章末尾:附上dll文件下载
附上主要实现方法,调用即可:
/// <summary>/// 转换图片格式/// </summary>/// <param name="oldPath">原图片路径</param>/// <param name="newPath">新图片路径</param>public static bool changeFormat(string oldPath, string newPath){try{//** psd convert to jpg 、gift、pngMagickNet.Magick.Init();//** find old path//** eg:"~/Images/yz1309.psd"MagickNet.Image img = new MagickNet.Image(HttpContext.Current.Server.MapPath(oldPath));//** set new image sizeSystem.Drawing.Size size = new System.Drawing.Size(220, 176);img.Resize(size);string path = newPath.Substring(0, newPath.LastIndexOf("/"));//** create directory if not existstring savePath = HttpContext.Current.Server.MapPath(path);if (!Directory.Exists(savePath))Directory.CreateDirectory(savePath);//** save new file //** eg:"~/Images/yz1309.jpg"img.Write(HttpContext.Current.Server.MapPath(newPath));MagickNet.Magick.Term();return true;}catch { return false; }}
调用方法:
bool res = changeFormat("~/Images/yz1309.psd", "~/Images/yz1309.jpg");
DLL下载地址