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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章