300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Asp.Net photoshop 源文件psd 图片 转换格式成jpg png gif

Asp.Net photoshop 源文件psd 图片 转换格式成jpg png gif

时间:2021-06-21 09:21:17

相关推荐

Asp.Net photoshop 源文件psd 图片 转换格式成jpg png gif

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下载地址

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。