国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.net在mvc環境下實現上傳頭像加剪裁功能的代碼實例

2024-07-10 12:54:47
字體:
來源:轉載
供稿:網友
好項目用到上傳+剪裁功能,發上來便于以后使用。我不能告訴你們其實是從博客園扒的前臺代碼,哈哈。前端是jquery+fineuploader+jquery.Jcrop

武林網web開發網為大家整理了這篇Asp.net在mvc環境下實現上傳頭像加剪裁功能的代碼實例,如果這篇文章在您的工作或學習中有幫助,歡迎常回來看看哦,更多精彩的教程請訪問我們的主頁,以下是教程瀏覽:

正好項目用到上傳+剪裁功能,發上來便于以后使用。

我不能告訴你們其實是從博客園扒的前臺代碼,哈哈。

前端是jquery+fineuploader+jquery.Jcrop

后臺是asp.net mvc 4

核心的js調用代碼是crop.js和helper文件夾下的ImgHandler.cs

效果圖

前臺代碼

<link href="~/Content/fineuploader.css" rel="stylesheet" /><link href="~/Content/jquery.Jcrop.min.css" rel="stylesheet" /><link href="~/Content/crop.min.css" rel="stylesheet" /><script src="~/Scripts/jquery-1.8.2.min.js"></script><script src="~/Scripts/jquery.fineuploader-3.1.min.js"></script><script src="~/Scripts/jquery.Jcrop.min.js"></script><script src="~/Scripts/crop.js"></script><div id="jquery-wrapped-fine-uploader"></div>    <div id="message"></div>    <div id="crop_wrap">        <div id="crop_holder">            <div id="crop_area" class="border">                <img id="crop_image" alt="" src="" class="preview-image" style="display: none" />            </div>            <div id="preview_area">                <div id="preview_title">當前頭像</div>                <div id="preview_large_text" class="preview-text">180px × 180px</div>                <div id="preview_large_wrap" class="border">                    <img id="preview_large"  alt="" src="@ViewBag.Path" class="preview-image" style=""/></div>            </div>        </div>        <div id="crop_operation" style="display: none;">            <form id="form_crop" action="/home/index" method="post">                <input type="hidden" name="x" id="x">                <input type="hidden" name="y" id="y">                <input type="hidden" name="w" id="w">                <input type="hidden" name="h" id="h">                <input type="hidden" name="imgsrc" id="imgsrc">                <input id="crop_operation_submit" type="submit" value="裁切并保存" /><span id="crop_operation_msg" style="display: none" class="green"></span>            </form>        </div>        <div id="croped_message" class="green"></div>    </div>

后臺代碼

public ActionResult Index()        {            return View();        }        /// <summary>        /// 保存縮略圖        /// </summary>        /// <param name="form"></param>        /// <returns></returns>        [HttpPost]        public ActionResult Index(FormCollection form)        {            int x = Convert.ToInt32(form["x"]);            int y = Convert.ToInt32(form["y"]);            int w = Convert.ToInt32(form["w"]);            int h = Convert.ToInt32(form["h"]);            string imgsrc = form["imgsrc"].Substring(0, form["imgsrc"].LastIndexOf("?"));            string path = ImgHandler.CutAvatar(imgsrc, x, y, w, h);            //保存Path                        ViewBag.Path = path;            return View();        }        /// <summary>        /// 上傳頭像        /// </summary>        /// <param name="qqfile"></param>        /// <returns></returns>        [HttpPost]        public ActionResult ProcessUpload(string qqfile)        {            try            {                string uploadFolder = "/Upload/original/" + DateTime.Now.ToString("yyyyMM") + "/";                string imgName = DateTime.Now.ToString("ddHHmmssff");                string imgType = qqfile.Substring(qqfile.LastIndexOf("."));                string uploadPath = "";                uploadPath = Server.MapPath(uploadFolder);                if (!Directory.Exists(uploadPath))                {                    Directory.CreateDirectory(uploadPath);                }                using (var inputStream = Request.InputStream)                {                    using (var flieStream = new FileStream(uploadPath + imgName + imgType, FileMode.Create))                    {                        inputStream.CopyTo(flieStream);                    }                }                return Json(new { success = true, message = uploadFolder + imgName + imgType });            }            catch (Exception e)            {                return Json(new { fail = true, message = e.Message });            }        }

代碼不全,這里是源碼:下載地址 ,http://down.VeVb.com/a/2018090669.shtml

教程內容到此結束,歡迎您再次訪問http://m.survivalescaperooms.com,我們致力于提供豐富的web開發教程及資源。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 盐亭县| 苍山县| 镇巴县| 西畴县| 屏边| 长乐市| 阿鲁科尔沁旗| 宁安市| 洛川县| 大英县| 茶陵县| 寿光市| 平湖市| 罗源县| 南昌县| 齐河县| 连山| 安顺市| 随州市| 青阳县| 鸡泽县| 资中县| 台湾省| 绥棱县| 枞阳县| 嵩明县| 双辽市| 潜山县| 广宗县| 平阳县| 灵寿县| 新疆| 岐山县| 满洲里市| 大埔区| 灵宝市| 冕宁县| 顺义区| 通化县| 舟山市| 阳朔县|