裁剪图片

/// <summary>
        /// 裁剪图片 返回服务器保存的路径
        /// </summary>
        /// <param name="url"></param>
        /// <param name="startX"></param>
        /// <param name="startY"></param>
        /// <param name="iWidth"></param>
        /// <param name="iHeight"></param>
        /// <param name="filename">文件名</param>
        /// <param name="dirpath">保存路径</param>
        /// <returns></returns>
        public static string ImgCut(Bitmap bit, int startX, int startY, int iWidth, int iHeight, string filename = "1.jpeg", string dirpath = "图片保存目录")
        {
            var img = Cut(bit, startX, startY, iWidth, iHeight);
            if (!Directory.Exists(HttpContext.Current.Server.MapPath(dirpath)))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(dirpath));
            }
            var filepath = dirpath + "/" + filename;
            img.Save(HttpContext.Current.Server.MapPath(filepath), ImageFormat.Jpeg);
            img.Clone();
            img.Dispose();

            return filepath;
        }

 

posted @ 2016-04-18 16:32  鞍山老菜鸟  阅读(165)  评论(0编辑  收藏  举报