Croppic插件使用介绍-asp.net
具体的参数使用和基本使用方式请看:http://www.uedsc.com/croppic-api.html
需要说明的几点:
1.支持两种上传方式:
(1)先将原图上传至服务器,然后再次将切图信息传给服务器。(两次请求,需要提供uploadUrl
和cropUrl
两个)
(2)直接将图片通过Data URI scheme的方式将图片缓存在浏览器内,用户切图完毕后同切图信息一并发送至服务器。(一次请求,只需要提供cropUrl
)
2.如果需要自定义切图的模板大小,需要修改croppic.js文件,修改如下:
然后在你程序使用的页面内灵活给这两个参数赋值就可以了。
3.后台程序处理的代码共享(注:使用了第二种,一次性上传的方式)
前台:
<div id="croppic"></div>
<script type="text/javascript">
@{
if (brand.Type==0)
{
<text>
var my_cropH = 203;
var my_cropW = 282;
</text>
}else {
<text>
var my_cropH = 300;
var my_cropW = 224;
</text>
}
}
var croppicHeaderOptions = {
cropData: {
"Id": '@brand.Id'
},
cropUrl: '/Brand/CutImg',
//customUploadButtonId: 'cropContainerHeaderButton',
modal: false,
processInline: true,
loaderHtml: '<div class="loader bubblingG"><span id="bubblingG_1"></span><span id="bubblingG_2"></span><span id="bubblingG_3"></span></div> ',
onBeforeImgUpload: function () { console.log('onBeforeImgUpload') },
onAfterImgUpload: function () { console.log('onAfterImgUpload') },
onImgDrag: function () { console.log('onImgDrag') },
onImgZoom: function () { console.log('onImgZoom') },
onBeforeImgCrop: function () { console.log('onBeforeImgCrop') },
onAfterImgCrop: function () { console.log('onAfterImgCrop') },
onReset: function () { console.log('onReset') },
onError: function (errormessage) { console.log('onError:' + errormessage) }
}
var croppic = new Croppic('croppic', croppicHeaderOptions);
</script>
后台:
public ActionResult CutImg(int? imgInitW, int? imgInitH, decimal? imgW, decimal? imgH, int? imgY1, int? imgX1, decimal? cropH, decimal? cropW, int? rotation)
{
//保存图片
var displayImageStream = Request["imgUrl"] == null ? null : Request["imgUrl"];
byte[] imgByte = Convert.FromBase64String(displayImageStream.Substring(displayImageStream.IndexOf(",") + 1));
Image oldImage;
using (MemoryStream mstream = new MemoryStream(imgByte, 0, imgByte.Length))
{
oldImage = Image.FromStream(mstream);
if (!oldImage.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
{
return Json(new { status = "error", message = "切图出现问题" });
}
}
//构建新的图片
var croppedBitmap = new Bitmap((int)cropW, (int)cropH);
try
{
using (var g = Graphics.FromImage(croppedBitmap))
{
Bitmap bitmap = new Bitmap(oldImage, (int)imgW, (int)imgH);
g.DrawImage(bitmap,
new Rectangle(0, 0, (int)cropW, (int)cropH),
new Rectangle((int)imgX1, (int)imgY1, (int)cropW, (int)cropH), GraphicsUnit.Pixel);
}
}
catch (Exception e)
{
return Json(new { status = "error", message = "internal error cropping the image" });
}
string relativePic = DateTime.Now.ToString("yyyy/MM/dd/") + Guid.NewGuid().ToString() + ".jpg";
string strNewPic = AppDomain.CurrentDomain.BaseDirectory + relativePic;
if (!Directory.Exists(Path.GetDirectoryName(strNewPic)))
Directory.CreateDirectory(Path.GetDirectoryName(strNewPic));
croppedBitmap.Save(strNewPic);
return Json(new { status = "success", url = "../../" + relativePic });
}
学习:https://codeload.github.com/danielbcorreia/croppic-net/zip/master 从这个链接学习了部分代码,感谢。
Croppic插件使用介绍-asp.net的更多相关文章
- 头像截图上传三种方式之一(一个简单易用的flash插件)(asp.net版本)
flash中有版权声明,不适合商业开发.这是官网地址:http://www.hdfu.net/ 本文参考了http://blog.csdn.net/yafei450225664/article/det ...
- 3.介绍ASP.NET Core框架
介绍ASP.NET Core框架 在这篇文章中,我将要向你们简短介绍一下ASP.NET Core 框架.当今社会,当提到软件开发,每个人都是讨论着开源以及跨平台开发.总所周知,微软是以它的基于Wind ...
- ASP.NET 5 已死 - 隆重介绍 ASP.NET Core 1.0 和 .NET Core 1.0
还没正式登场就死了?不能怪我标题党,是大神Scott在他博客上这么说的,我只是翻译了一下. 在1月20号最新的ASP.NET Community Standup视频中,微软aspnet开发组的大帅哥 ...
- 【转】Eclipse插件大全介绍及下载地址
转载地址:http://developer.51cto.com/art/200906/127169.htm 尚未一一验证. eclipse插件大全介绍,以及下载地址 Eclipse及其插件下载网址大全 ...
- Xcode Alcatraz插件管理介绍和使用
Xcode Alcatraz插件管理介绍和使用http://www.jianshu.com/p/7a2484123bf6 1.简介 Alcatraz是一个能帮你管理Xcode插件丶模版及颜色配置的工具 ...
- 详细介绍ASP.NET页面重定向方法
ASP.NET中页面重定向的使用的很频繁,实现方法也有不同,自己也试过几种,现在总结一下. 一.Transfer Execute Redirect重定向方法介绍 1.Server.Transfer方法 ...
- 03_Elasticsearch如何安装以及相关插件的介绍
03_Elasticsearch如何安装以及相关插件的介绍 elasticsearch -d (-d参数是为了让服务后台运行) Elasticsearch 目录结构: 文件夹 作用 /bin 运行El ...
- 图片剪切之Croppic插件
前几天做图片上传时需要进行图片的剪切和缩放,上网查找时找到了这个插件.样式很好看,功能也很OK.但是网上都是php进行后台处理图片的例子,然后只好慢慢琢磨C#的处理.插件地址是:http://www. ...
- Cordova各个插件使用介绍系列(六)—$cordovaDevice获取设备的相关信息
详情请看:Cordova各个插件使用介绍系列(六)—$cordovaDevice获取设备的相关信息 在项目中需要获取到当前设备,例如手机的ID,联网状态,等,然后这个Cordova里有这个插件可以用, ...
随机推荐
- codeforces 689 Mike and Shortcuts(最短路)
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路 ...
- HUST 1214 Cubic-free numbers II
Cubic-free numbers II Time Limit: 10000ms Memory Limit: 131072KB This problem will be judged on HUST ...
- Bellman_ford 算法 Currency Exchange POJ1860
Bellman_ford算法用于寻找正环或者负环! 算法导论: 24.1 The Bellman-Ford algorithm The Bellman-Ford algorithm solves th ...
- C++ new malloc realloc
int* a = new int; 分配了存储空间,但没有赋初值 int* a = new int(10) 分配了存储空间,并赋初值,即*a = 10 int* a = ne ...
- Linux自己主动挂载第二块硬盘分区
改动/etc/fstab文件,如果挂载到/data文件夹.在最后一行加上 /dev/sdb1 /data ext4 defaults 1 1 最后结果例如以下: # # /etc/fstab # Cr ...
- zookeeper+kafka配置
ZooKeeper 安装 #将ZooKeeper解压到/usr/local中 tar –zxvf zookeeper-3.4.6.tar.gz –C /usr/local cd /usr/local ...
- 解决多个Xcode导致的N个模拟器的问题
<欢迎大家增加iOS开发学习交流群:QQ529560119> 完美解决多个Xcode从而导致了出现N个模拟器的问题
- Android Studio VS Eclipse (还在用Eclipse?你OUT了!)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990).谢谢支持! 公司派来一个去美国參加完AnDevCon大会的来给我们分享大会上学习的内容. AnDevC ...
- Android面试题1
1.Android中intent的是? 答:实现界面间的切换,能够包括动作和动作数据.连接四大组件的纽带. 2.SAX解析xml文件的长处的是? 答:不用事先调入整个文档,占用资源少 3.在andro ...
- GPS时间
GPS信息里面包含一个时间戳. phonegap(即cordova)的地理位置API Geolocation 提供了对设备GPS传感器的访问,返回的数据中,除了坐标,还有一个时间戳timestamp. ...