濮阳杆衣贸易有限公司

主頁 > 知識庫 > 實現(xiàn)Asp.net mvc上傳頭像加剪裁功能

實現(xiàn)Asp.net mvc上傳頭像加剪裁功能

熱門標簽:南昌自動外呼系統(tǒng)線路 上海市三維地圖標注 辦公用地圖標注網(wǎng)點怎么操作 云南外呼系統(tǒng)代理 聊城智能電銷機器人電話 西寧電銷外呼系統(tǒng)公司 海東防封電銷卡 寧德防封版電銷卡 安陸市地圖標注app

在我們使用QQ上傳頭像,注冊用戶賬號時是不是都會遇到上傳圖像,并根據(jù)自己的要求對圖像進行裁剪,這是怎么實現(xiàn)的吶?

本文主要介紹了Asp.net mvc實現(xiàn)上傳頭像加剪裁功能,分享給大家供大家參考。具體如下: 

運行效果截圖如下:

具體代碼如下:

前臺代碼

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 });
   }
  }

以上就是實現(xiàn)Asp.net mvc上傳頭像加剪裁功能的部分代碼,小編分享給大家參考,希望對大家的學習有所幫助。

您可能感興趣的文章:
  • web前端開發(fā)upload上傳頭像js示例代碼
  • php視頻拍照上傳頭像功能實現(xiàn)代碼分享
  • php+js iframe實現(xiàn)上傳頭像界面無跳轉
  • JS仿flash上傳頭像效果實現(xiàn)代碼
  • 淺析上傳頭像示例及其注意事項

標簽:崇左 青海 汕尾 衢州 洛陽 贛州 南寧

巨人網(wǎng)絡通訊聲明:本文標題《實現(xiàn)Asp.net mvc上傳頭像加剪裁功能》,本文關鍵詞  實現(xiàn),Asp.net,mvc,上傳,頭像,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《實現(xiàn)Asp.net mvc上傳頭像加剪裁功能》相關的同類信息!
  • 本頁收集關于實現(xiàn)Asp.net mvc上傳頭像加剪裁功能的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    合作市| 武安市| 抚宁县| 四会市| 年辖:市辖区| 金山区| 黔南| 新疆| 澜沧| 鄱阳县| 卓尼县| 井冈山市| 拜城县| 定陶县| 余庆县| 城步| 天台县| 若尔盖县| 绥德县| 潞城市| 瓦房店市| 杭锦后旗| 乐安县| 海南省| 噶尔县| 鹿泉市| 安平县| 龙游县| 山西省| 延边| 安福县| 阿荣旗| 彭山县| 南靖县| 望都县| 安西县| 台州市| 崇阳县| 石棉县| 双柏县| 贞丰县|