在我们使用QQ上传头像,注册用户账号时是不是都会遇到上传图像,并根据自己的要求对图像进行裁剪,这是怎么实现的呐?
本文主要介绍了Asp.net mvc实现上传头像加剪裁功能,分享给大家供大家参考。具体如下:
运行效果截图如下:
具体代码如下:
前台代码
<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="/UploadFiles/2021-04-02/jquery-1.8.2.min.js">后台代码
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 }); } }以上就是实现Asp.net mvc上传头像加剪裁功能的部分代码,小编分享给大家参考,希望对大家的学习有所帮助。
最新资源
- 白嘉倩.1992-我有我【星工厂】【WAV+CUE】
- 黎明.2006-LOOKING【东亚唱片】【WAV+CUE】
- 群星.1986-国语金曲尽精英【瑞成】【WAV+CUE】
- 長渕剛《Blood》[FLAC/分轨][299.09MB]
- 群星《歌手2024 第4期》[320K/MP3][107.39MB]
- 群星《歌手2024 第4期》[FLAC/分轨][563.76MB]
- RiffKitten-ChaosParade(2024)[24-44,1]FLAC
- RuneKlakegg-Nattevandrer(2024)[24-96]\FLAC
- 赖冰霞.2006-金嗓典藏辑2IN1(南方金点系列)2CD【
- 群星.1988-国语金曲尽精英VOL.2【瑞成】【WAV+C