SwfUpload及imgareaselect使用方法
1、导入文件
Swfupload相关文件

imgareaselect截取插件相关文件

2、前端html代码
添加一个截取图片的按钮,其他为swf所需的html。
<body>
<div id="content">
<div id="swfu_container" style="margin: 0px 10px;">
<div>
<span id="spanButtonPlaceholder"></span>
</div>
<div id="divFileProgressContainer" style="height: 75px;"></div>
</div>
</div>
<input type="button" value="截取图像" id="imgbtn" />
</body>
3、前端js代码
使用的jq版本1.7的,我在使用1.10的时候,截图的框不能出来。上传成功后,显示图片,并且调用截取函数。为截取按钮绑定click函数,把宽、高、位置坐标,及路径地址等相关数据提交到后台,后台接受数据,根据这些数据截取图片。
<script type="text/javascript">
var swfu, select;
window.onload = function () {
swfu = new SWFUpload({
// Backend Settings
upload_url: "/upload.ashx",
post_params: {
"ASPSESSID": "<%=Session.SessionID %>"
}, // File Upload Settings
file_size_limit: "2 MB",
file_types: "*.jpg",
file_types_description: "JPG Images",
file_upload_limit: 0, // Zero means unlimited // Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
swfupload_preload_handler: preLoad,
swfupload_load_failed_handler: loadFailed,
file_queue_error_handler: fileQueueError,
file_dialog_complete_handler: fileDialogComplete,
upload_progress_handler: uploadProgress,
upload_error_handler: uploadError,
upload_success_handler: function (file, serverdata) {
$("#divFileProgressContainer").text("").css('height', '100%');
$("#divFileProgressContainer img").remove();
$("#divFileProgressContainer").append("<img id='imgselect' style='width:300px;height:100%;' src='" + serverdata + "' />");
select = $('#imgselect').imgAreaSelect({
selectionColor: 'white', x1: 0, y1: 0, x2: 100, y2: 100,
maxWidth: 180, minWidth: 180, minHeight: 180, maxHeight: 180,
selectionOpacity: 0.2, onSelectEnd: function (img, selection) { $('#imgselect').data('x', selection.x1); $('#imgselect').data('y', selection.y1); $('#imgselect').data('w', selection.width); $('#imgselect').data('h', selection.height); }
});
},
upload_complete_handler: function () { }, // Button settings
button_image_url: "/scripts/swfupload/images/XPButtonNoText_160x22.png",
button_placeholder_id: "spanButtonPlaceholder",
button_width: 80,
button_height: 22,
button_text: '<span class="button">图片上传</span>',
button_text_style: '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
button_text_top_padding: 1,
button_text_left_padding: 5, // Flash Settings
flash_url: "/scripts/swfupload/swfupload.swf", // Relative to this file
flash9_url: "/scripts/swfupload/swfupload_FP9.swf", // Relative to this file custom_settings: {
upload_target: "divFileProgressContainer"
},
// Debug Settings
debug: false
}); }
$(function () {
$("#imgbtn").click(function () {
if (!$('#imgselect').data('w')) { //用户没有选择 那么按照默认来
$('#imgselect').data('x', 0); $('#imgselect').data('y', 0); $('#imgselect').data('w', 100); $('#imgselect').data('h', 100);
}
var pic = $('#imgselect').attr('src');
var x, y, w, h;
$.post(
"/CutImg.ashx",
{
x: $('#imgselect').data('x'), y: $('#imgselect').data('y'), w: $('#imgselect').data('w'), h: $('#imgselect').data('h'), pic: pic },
function (data) {
//把裁剪后图片加载到原处
if (data) {
$('#imgselect').imgAreaSelect({ hide: true }); //截取成功隐藏截取框
$('#imgselect').attr('src', data).css('width', '180px').css('height', '180px');
alert("截取成功");
} }); });
});
</script>
4、上传的后台代码
使用ashx一般处理程序来处理上传图片,以文件的md5值命名图片。保存完成,把图片的相对地址发送到前端。
HttpPostedFile file = context.Request.Files["Filedata"];
if (file == null)
{
context.Response.Write("上传失败");
}
else
{
string filename = Path.GetFileName(file.FileName);
string ext = Path.GetExtension(filename);
filename = MD5Helper.GetStreamMD5(file.InputStream);
string path = "/UploadImage/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day +
"/";
Directory.CreateDirectory(context.Server.MapPath(path));
file.SaveAs(context.Server.MapPath(path + filename + ext));
context.Response.Write(path + filename + ext);
}
5、图片截取后台代码
同样使用一般处理程序来处理,首先取得,用户截取的宽高,位置坐标、图片的相对路径。新建画布、画笔、加载图片。在画布上用画笔,画图片。用大图片的文件名作为小图片的文件名,存放在small文件夹内。最后把小图片的相对地址,返回到前台。
int x = Convert.ToInt32(context.Request["x"]);
int y = Convert.ToInt32(context.Request["y"]);
int width = Convert.ToInt32(context.Request["w"]);
int height = Convert.ToInt32(context.Request["h"]);
string path =context.Request["pic"]; using (Bitmap b=new Bitmap(width,height))
{
using (Graphics g=Graphics.FromImage(b))
{
using (Image i = Image.FromFile(context.Server.MapPath(path)))
{
//1、哪张图片2、画多大 3、从哪里开始画
g.DrawImage(i,new Rectangle(,,width,height),new Rectangle(x,y,width,height),GraphicsUnit.Pixel ); string bigName = path.Substring(path.LastIndexOf('/')+,path.LastIndexOf('.')--path.LastIndexOf('/')); string pathsmall = "/UploadImage/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day +
"/"+"small/";
Directory.CreateDirectory(context.Server.MapPath(pathsmall));
//不能删除大的 会提示正在被访问 b.Save(context.Server.MapPath(pathsmall + bigName + ".jpg"));
context.Response.Write(pathsmall + bigName + ".jpg"); }
}
}
SwfUpload及imgareaselect使用方法的更多相关文章
- SWFUpload
引用:http://www.cnblogs.com/2050/archive/2012/08/29/2662932.html SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非 ...
- SWFUpload使用指南
SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非常强大. SWFUpload的特点: 1.用flash进行上传,页面无刷新,且可自定义Flash按钮的样式; 2.可以在浏览器 ...
- swfupload 参数说明
一.配置参数对象中的常用属性及说明 属性 类型 默认值 描述 upload_url String 处理上传文件的服务器端页面的url地址,可以是绝对地址,也可以是相对地址,当为相对地址时相对的是当 ...
- swfupload使用说明
网上的例子介绍的文档真的很多.下面简单介绍一下 SWFUpload的文件上传流程是这样的: 1.引入相应的js文件 2.实例化SWFUpload对象,传入一个配置参数对象进行各方面的配置. 3.点击S ...
- SWFUpload(转载)
网上的例子介绍的文档真的很多.下面简单介绍一下 SWFUpload的文件上传流程是这样的: 1.引入相应的js文件 2.实例化SWFUpload对象,传入一个配置参数对象进行各方面的配置. 3.点击S ...
- 文件上传利器SWFUpload使用指南(转)
http://www.cnblogs.com/2050/archive/2012/08/29/2662932.html 文件上传利器SWFUpload使用指南 SWFUpload是一个flash和js ...
- 浅谈如何使用swfupload工具与struts2无缝相接
笔者在网上查找流行的上传组件,swfupload引入眼帘,受到JavaEye的一篇文章启发,历时三天,加以研究,现将心得奉上,献礼JavaEye. 由于笔者才疏学浅,经验匮乏,介绍不深入,仅供菜鸟参考 ...
- SWFUpload文件上传详解
SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非常强大. SWFUpload的特点: 1.用flash进行上传,页面无刷新,且可自定义Flash按钮的样式; 2.可以在浏览器 ...
- 【转】SWFUpload使用指南
原文出自:http://www.runoob.com/w3cnote/swfupload-guide.html SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非常强大.以前在 ...
随机推荐
- Pycharm在创建py文件时,如何自动添加文件头注释(类似于钩子特性)?
在每次新建一个py文件的时候 1 如何自动添加/usr/bin/env python2 自动添加 coding=utf8 操作方法: File->settings->Editor-> ...
- windows7下python环境变量配置
默认情况下,在windows下安装python之后,系统并不会自动添加相应的环境变量.此时不能在命令行或cmd里直接使用python命令. 1. 首先需要在系统中注册python环境变量:假设pyth ...
- 列表框List Box
List Box/Check List Box ListBox窗口用来列出一系列的文本,每条文本占一行.创建一个列表窗口可以使用成员函数: BOOL CListBox::Create( LPCTSTR ...
- 使用hexo创建github博客
前言 前面说过,之前用wordpress辛辛苦苦搭建的博客,因为服务器和域名的问题挂掉了.后来发现github也能够搭建自己的博客,不需要去关心主机域名的问题,而且还能使用Markdown来写博客,就 ...
- Linux iptables 应用控制访问SSH服务
Title:Linux iptables 应用控制访问SSH服务 --2012-02-23 17:51 今天用到了以前从来没有用到过的,iptables控制访问,只允许外部访问SSH服务(22号端口 ...
- webserver and application server
http://www.diffen.com/difference/Application_Server_vs_Web_Server http://www.differencebetween.com/d ...
- smart pointer (auto_ptr)
很多人听说过标准auto_ptr智能指针机制,但并不是每个人都天天使用它.这真是个遗憾,因为auto_ptr优雅地解决了C++设计和编码中常见的问题,正确地使用它可以生成健壮的代码.本文阐述了如何正确 ...
- rsyslog imfile 模块说明
stop() { echo -n $"Shutting down system logger: " killproc -p "${PIDFILE}" -d 30 ...
- Invalid file system control data detected
今天在做mkdir操作时报错:Invalid file system control data detected.检查用户和权限没问题,再检查磁盘空间也没问题.最后在网上找到如下信息: [proble ...
- URAL 2034 : Caravans
Description Student Ilya often skips his classes at the university. His friends criticize him for ...