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使用方法的更多相关文章

  1. SWFUpload

    引用:http://www.cnblogs.com/2050/archive/2012/08/29/2662932.html SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非 ...

  2. SWFUpload使用指南

    SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非常强大. SWFUpload的特点: 1.用flash进行上传,页面无刷新,且可自定义Flash按钮的样式; 2.可以在浏览器 ...

  3. swfupload 参数说明

    一.配置参数对象中的常用属性及说明 属性 类型 默认值 描述 upload_url String   处理上传文件的服务器端页面的url地址,可以是绝对地址,也可以是相对地址,当为相对地址时相对的是当 ...

  4. swfupload使用说明

    网上的例子介绍的文档真的很多.下面简单介绍一下 SWFUpload的文件上传流程是这样的: 1.引入相应的js文件 2.实例化SWFUpload对象,传入一个配置参数对象进行各方面的配置. 3.点击S ...

  5. SWFUpload(转载)

    网上的例子介绍的文档真的很多.下面简单介绍一下 SWFUpload的文件上传流程是这样的: 1.引入相应的js文件 2.实例化SWFUpload对象,传入一个配置参数对象进行各方面的配置. 3.点击S ...

  6. 文件上传利器SWFUpload使用指南(转)

    http://www.cnblogs.com/2050/archive/2012/08/29/2662932.html 文件上传利器SWFUpload使用指南 SWFUpload是一个flash和js ...

  7. 浅谈如何使用swfupload工具与struts2无缝相接

    笔者在网上查找流行的上传组件,swfupload引入眼帘,受到JavaEye的一篇文章启发,历时三天,加以研究,现将心得奉上,献礼JavaEye. 由于笔者才疏学浅,经验匮乏,介绍不深入,仅供菜鸟参考 ...

  8. SWFUpload文件上传详解

    SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非常强大. SWFUpload的特点: 1.用flash进行上传,页面无刷新,且可自定义Flash按钮的样式; 2.可以在浏览器 ...

  9. 【转】SWFUpload使用指南

    原文出自:http://www.runoob.com/w3cnote/swfupload-guide.html SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非常强大.以前在 ...

随机推荐

  1. 在 html 中用加色法混合颜色

    概要 本文通过解决一个假想的问题介绍了 css screen 混合模式,并介绍了如何用 svg 滤镜.canvas 2d.canvas webgl 实现相同的效果. 问题 下面的图片演示三种颜色光叠加 ...

  2. phpcms v9 读取地区联动菜单缓存文件

    读取缓存文件的方法是 getcache() 在 phpcms\libs\functions\global.func.php 中可找到. 地区联动菜单的缓存文件是  caches\caches_link ...

  3. phpcms v9开源开发框架基础mvc解读

    根据对mvc的了解 简要写个mvc框架 也谈不上框架 希望对新手有帮助 简单的解析下mvc  你可以这样了解 m模型也就是数据库操作 v视图  c控制器 通过url来判断调用m和v来完成请求,本身没数 ...

  4. C#7.0

    C#7.0中有哪些新特性? 以下将是 C# 7.0 中所有计划的语言特性的描述.随着 Visual Studio “15” Preview 4 版本的发布,这些特性中的大部分将活跃起来.现在是时候来展 ...

  5. 2017-1-9css

    2017-1-9css css border-image详解 http://www.360doc.com/content/14/1016/13/2792772_417403574.shtml 最简单的 ...

  6. MPMoviePlayerController 电影播放器—备用

    MPMoviePlayerController 与AVAudioPlayer有点类似,前者播放视频,后者播放音频,不过也有很大不同,MPMoviePlayerController 可以直接通过远程UR ...

  7. empty()方法

    empty()可以用来检查一个变量是否被声明或者值为false,通常被用来检查一个表单变量是否被发送或者包含数据. 例如一个登录表单: <?php if(!empty($_POST['uname ...

  8. Android中开发Service

    Service的开发分为两个步骤:定义Service和配置Service1.定义Service定义一个Service子类继承于Service2.配置Service在AndroidManifest.xm ...

  9. PL/SQL 包头和包体

    包用于逻辑组合相关的过程和函数,它由包规范和包体两部分组成,包规范用于定义公用的常量 变量,过程和函数,在SQL*PLUS中建立包规范可以使用CREATE PACKAGE命令. 实例如下: CREAT ...

  10. 近 100 个 Linux 常用命令大全

    1.ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a 列出包括.a开头的隐藏文件的所有文件 -A 通-a,但不列出"."和".." -l 列出 ...