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 });
}
}
asp.net mvc上传头像加剪裁功能介绍的更多相关文章
- asp.net mvc上传头像加剪裁功能
原文:asp.net mvc上传头像加剪裁功能 正好项目用到上传+剪裁功能,发上来便于以后使用. 我不能告诉你们其实是从博客园扒的前台代码,哈哈. 前端是jquery+fineuploader+jqu ...
- mvc上传头像加剪裁功能
asp.net mvc上传头像加剪裁功能 正好项目用到上传+剪裁功能,发上来便于以后使用. 我不能告诉你们其实是从博客园扒的前台代码,哈哈. 前端是jquery+fineuploader+jquery ...
- .net mvc 上传头像
我用的是mvc5 开发环境vs2017 [仅供参考] [视图代码] <div > <img src="@path" alt="@att.Count&q ...
- asp.net MVC 上传文件 System.Web.HttpException: 超过了最大请求长度
APS.NET MVC 上传文件出现 System.Web.HttpException: 超过了最大请求长度 这个问题 原因是 默认最大上传文件大小为4096,而我提交的文件太大了. 解决方案:修改 ...
- ASP.NET MVC上传文件----uploadify的使用
课程设计需要实现上传文件模块,本来ASP.NET是有内置的控件,但是ASP.NET MVC没有,所以就有两种方法:自定义和采用第三方插件.由于时间的关系,故采用第三方插件:uploadify. upl ...
- ASP.NET MVC上传文件
最近参考网络资料,学习了ASP.NET MVC如何上传文件.最基本的,没有用jQuery等技术. 1.定义Model public class TestModel { [Displ ...
- ASP.NET MVC 上传大文件时404
前一段时间会员的上传组件改用FLASH的swfupload来上传,既能很友好的显示上传进度,又能完全满足大文件的上传. 后来服务器升级到windows 2008,改为IIS7后,上传文件一旦超过30M ...
- asp.net mvc 上传文件
转至:http://www.cnblogs.com/fonour/p/ajaxFileUpload.html 0.下载 http://files.cnblogs.com/files/fonour/aj ...
- Asp.net mvc上传多张图片后台存储
前台页面通过<file name="img">标签数组上传图片,后台根据Request.Files["img"]来接收前台上传的图片. 1 Syst ...
随机推荐
- jQuery遍历json
使用 each var anObject = {one:1,two:2,three:3}; $.each(anObject,function(name,value) { alert(name); al ...
- poj 3984 迷宫问题 bfs
学会这道水题之后我懂得了不少哈,首先水题也能学到不少知识,尤其像我这样刚入门的小菜鸟,能学到一些小技巧. 然后就是可以从别人的代码里学到不一样的思路和想法. 这题就是求最短的路径,首先想到就是用bfs ...
- android的ListView做表格添加圆角边框
边框,圆角,都可以实现的 在drawable目录下添加view_yuan_morelist.xml,设置控件的边框代码.如下: <?xml version="1.0" enc ...
- 应聘.net开发工程师常见的面试题(五)
1.描述一下C#中索引器的实现过程,是否只能根据数字进行索引? 答:不是.可以用任意类型. 2.在C#中,string str = null 与 string str = ” ” 请尽量使用文字或图象 ...
- Linux 服务器相关的一下链接
Apache 虚拟主机 VirtualHost 配置 以下是各操作系统的配置方法. Redhat Enterprise Linux Ubuntu Linux Windows Mac OS http:/ ...
- Spring中Bean的生命中期与InitializingBean和DisposableBean接口
Spring提供了一些标志接口,用来改变BeanFactory中的bean的行为.它们包括InitializingBean和DisposableBean.实现这些接口将会导致BeanFactory调用 ...
- msp430f149的低功耗模式
430的低功耗确实很强啊,虽然和VR单片机比起来速度慢了好多.在CPU进行工作时,如果没有什么事情干,就得进入低功耗模式啦,LMPX(0~4)这几种模式的具体事项就是如下的,得记住了. 一,运行模式M ...
- 嵌入式中 MMU的功能
学习嵌入式才发现要看的书太多,外面的世界很精彩啊,现在来说说MMU吧,MMU是Memory Management Unit的缩写,是用来管理虚拟内存系统的器件. MMU通常是CPU的一部分,本身有少量 ...
- highcharts 去掉右下角链接
去掉右下角的highcharts.com链接需要加入以下代码: credits: { enabled:false }, 如果不设置,那么默认为显示.
- 论js中的prototype
今天在阅读代码时,碰到了prototype //判断是否是数组function isArray(obj) { return Object.prototype.toString.call(obj) == ...