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、png
                MagickNet.Magick.Init();
                //** find old path
                //** eg:"~/Images/yz1309.psd"
                MagickNet.Image img = new MagickNet.Image(HttpContext.Current.Server.MapPath(oldPath));
                //** set new image size
                System.Drawing.Size size = new System.Drawing.Size(220, 176);
                img.Resize(size);
                string path = newPath.Substring(0, newPath.LastIndexOf("/"));
                //** create directory if not exist
                string 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下载地址

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值