基本信息
源码名称:Asp.Net无刷新上传并裁剪头像(用Jquery插件 Uploadify实现) 附完整源码
源码大小:4.55M
文件格式:.rar
开发语言:C#
更新时间:2013-04-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
用jquery插件 Uploadify实现无刷新上传头像,并可裁剪图片大小, 官方网站详见:http://www.uploadify.com/
常用方法有:
| 名称 | 介绍 | 类型 |
| Uploadify常用属性 | ||
| uploader | uploadify的swf文件的路径 | string |
| cancelImg | 取消按钮图片路径 | string |
| folder | 上传文件夹路径 | string |
| multi | 是否多文件上传 | boolean |
| script | 上传文件处理代码的文件路径 | json |
| scriptData | 提交到script对应路径文件的参数 | 类型 |
| method | 提交scriptData的方式(get/post) | string |
| fileExt | 支持上传文件类型(格式:*.jpg;*.png) | string |
| fileDesc | 提示于点击上传弹出选择文件框文件类型(自定义) | string |
| sizeLimit | 上传大小限制(byte为单位) | integer |
| auto | 是否选择文件后自动上传 | boolean |
| Uploadify常用事件 | ||
| onAllComplete | 上传完成后响应 | function |
| onCancel | 取消时响应 | function |
| Uploadify常用方法 | ||
| .uploadify() | 初始化uploadify上传 | |
| .uploadifyUpload() | 触发上传 | |
| .uploadifySettings() | 更新uploadify的属性 | |
<%@ WebHandler Language="C#" Class="CutAvatarHandler" %>
using System;
using System.Web;
using System.Web.SessionState;
public class CutAvatarHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
System.Drawing.Bitmap bitmap = null; //按截图区域生成Bitmap
System.Drawing.Image thumbImg = null; //被截图
System.Drawing.Graphics gps = null; //存绘图对象
System.Drawing.Image finalImg = null; //最终图片
try
{
string pointX = context.Request.Params["pointX"]; //X坐标
string pointY = context.Request.Params["pointY"]; //Y坐标
string imgUrl = context.Request.Params["imgUrl"]; //被截图图片地址
string rlSize = context.Request.Params["maxVal"]; //截图矩形的大小
int finalWidth = 100;
int finalHeight = 100;
if (!string.IsNullOrEmpty(pointX) && !string.IsNullOrEmpty(pointY) && !string.IsNullOrEmpty(imgUrl))
{
string ext = System.IO.Path.GetExtension(imgUrl).ToLower(); //上传文件的后缀(小写)
bitmap = new System.Drawing.Bitmap(Convert.ToInt32(rlSize), Convert.ToInt32(rlSize));
thumbImg = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(imgUrl));
System.Drawing.Rectangle rl = new System.Drawing.Rectangle(Convert.ToInt32(pointX), Convert.ToInt32(pointY), Convert.ToInt32(rlSize), Convert.ToInt32(rlSize)); //得到截图矩形
gps = System.Drawing.Graphics.FromImage(bitmap); //读到绘图对象
gps.DrawImage(thumbImg, 0, 0, rl, System.Drawing.GraphicsUnit.Pixel);
finalImg = PubClass.GetThumbNailImage(bitmap, finalWidth, finalHeight);
string finalPath = "/User/final" DateTime.Now.ToFileTime() ext;
finalImg.Save(HttpContext.Current.Server.MapPath(finalPath));
bitmap.Dispose();
thumbImg.Dispose();
gps.Dispose();
finalImg.Dispose();
GC.Collect();
PubClass.FileDel(HttpContext.Current.Server.MapPath(imgUrl));
context.Response.Write(finalPath);
}
}
catch (Exception)
{
throw;
}
}
public bool IsReusable
{
get
{
return false;
}
}
}