//jcrop 用法  lpf
//页面引入
//<link rel="stylesheet" href="${basePath}/scripts/jcrop/jquery.Jcrop.css" type="text/css" />
//<script src="${basePath}/scripts/jcrop/jquery.Jcrop.js"></script>
//图片位置<img src="" id="target" style="width: 100%;height:100%;"/>
//赋值框<form action="${basePath}/success.jsp" method="post" >
//x轴:<input type="text" size="4" id="x1" name="x" />
//y轴:<input type="text" size="4" id="y1" name="y"/>
//宽度:<input type="text" size="4" id="w" name="w"/>
//高度:<input type="text" size="4" id="h" name="h"/>
//显示图片宽:<input type="text" size="4" id="tw" name="tw"/>
//<input type="button" value="裁剪" onclick="uploadImage();"/>
//</form>
jQuery(function($){
//浏览器宽高
var width=$(window).width();
var height=$(window).height();
//图片工具对象
var jcrop_api,
boundx="",
boundy="",
$preview = $('#preview-pane'),
$pcnt = $('#preview-pane .preview-container'),
$pimg = $('#preview-pane .preview-container img'),
xsize = $pcnt.width(),
ysize = $pcnt.height();
$('#target').Jcrop({
onChange:showCoords,//获取选中的值
onSelect:showCoords,//获取拖拽的值
keySupport:true,
aspectRatio:,
boxWidth:width,
boxHeight:height
},function(){
var bounds = this.getBounds();
boundx = bounds[];
boundy = bounds[];
jcrop_api = this;
$preview.appendTo(jcrop_api.ui.holder);
});
//赋值
function showCoords(c){
var x=c.x;
var y=c.y;
var w=c.w;
var h=c.h;
$("#x1").val(parseInt(x));
$("#y1").val(parseInt(y));
$("#w").val(parseInt(w));
$("#h").val(parseInt(h));
if (parseInt(c.w) > ){
var rx = xsize / c.w;
var ry = ysize / c.h;
$pimg.css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
}
//更换图片设置
function upimg(img){
jcrop_api.setImage(img,function(){
this.setOptions({
bgOpacity:0.6,
minSize: [, ],
maxSize: [, ]
});
var bounds = this.getBounds();
boundx = bounds[];
$('#tw').val(boundx);
this.setSelect(getRandom());
});
}
//随机选择框
function getRandom() {
var dim = jcrop_api.getBounds();
return [
Math.round(Math.random() * dim[]),
Math.round(Math.random() * dim[]),
Math.round(Math.random() * dim[]),
Math.round(Math.random() * dim[])
];
};
});
 File fromPic = new File(fileSavePath);
BufferedImage image = ImageIO.read(fromPic);
int imageWidth = image.getWidth();
// 按比例缩放后 输出到 BufferedImage
BufferedImage thumbnail = Thumbnails.of(fileSavePath)
.scale(Double.valueOf(request.getParameter("tw"))
/ imageWidth)
.asBufferedImage();
// 截取图片路径,
fileSavePath = request.getSession().getServletContext()
.getRealPath("/upload")
+ "/" + upLoadPath + newfilename + "_thum.jpg";
//生成截取图片,按照坐标
Thumbnails
.of(thumbnail)
.sourceRegion(
Integer.valueOf(request.getParameter("x")),
Integer.valueOf(request.getParameter("y")),
Integer.valueOf(request.getParameter("w")),
Integer.valueOf(request.getParameter("h")))
.size(Integer.valueOf(request.getParameter("w")),
Integer.valueOf(request.getParameter("h")))
.keepAspectRatio(false)
.toFile(fileSavePath);

在页面进行截取的时候,如果所操作的图片与原图大小不一致,在后台进行截取的时候就会出现偏差,

此处拿到原图后会与页面显示的图片大小进行比较,计算比例,进行比例缩放,在进行截取

jcrop+java 后台的更多相关文章

  1. 如何用CropBox实现头像裁剪并与java后台交互

    如何用CropBox实现头像裁剪并与java后台交互 参考网站:https://developer.mozilla.org/zh-CN/docs/Web/API/Blob 参考: http://blo ...

  2. pagebean pagetag java 后台代码实现分页 demo 前台标签分页 后台java分页

    java 后台代码实现分页 demo 实力 自己写的 标签分页 package com.cszoc.sockstore.util; import java.util.HashMap;import ja ...

  3. ajax提交数据到java后台,并且返回json格式数据前台接收处理值

    1.前台html页面.有一段代码如下: 账  户:  <input type="text" name="userName" id="userN& ...

  4. java后台对前端输入的特殊字符进行转义

    转自:http://www.cnblogs.com/yangzhilong/p/5667165.html java后台对前端输入的特殊字符进行转义 HTML: 常见的帮助类有2个:一个是spring的 ...

  5. java后台获取Access_token的工具方法

    本方法主要通过java后台控制来获取Access_token,需要你已经知道自己的ID跟密码 因为微信的权限设置大概每天可以获取两千条,每条有效时间为2小时 /** * 输入自己的id跟密码,获取微信 ...

  6. js前台加密,java后台解密实现

    参考资料: JS前台加密,java后台解密实现

  7. java后台异步任务执行器TaskManager

    java后台异步任务执行器TaskManager 此方式基于MVC方式: 一,使用任务: @Resource private TaskManager taskManager; public strin ...

  8. fastJson java后台转换json格式数据

    什么事JSON? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Progra ...

  9. encodeURIComponent编码后java后台的解码 (AJAX中文解决方案)

    encodeURIComponent编码后java后台的解码 (AJAX中文解决方案) 同学的毕业设计出现JavaScript用encodeURIComponentt编码后无法再后台解码的问题. 原来 ...

随机推荐

  1. call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数

    <?php function foobar($arg, $arg2) { echo __FUNCTION__, " got $arg and $arg2\n"; } clas ...

  2. Unparseable date: "Mon Aug 15 11:24:39 CST 2016",时间格式转换异常

    String datestr= "Mon Aug 15 11:24:39 CST 2016";//Date的默认格式显示 Date date=new SimpleDateForma ...

  3. find命令查找目录

    find <path> -type d -name "dir_name" -type d是查找目录的参数,如果是查找其他的: -type b: Block specia ...

  4. 【优化】MySQL千万级大表优化解决方案

    问题概述 使用阿里云rds for MySQL数据库(就是MySQL5.6版本),有个用户上网记录表6个月的数据量近2000万,保留最近一年的数据量达到4000万,查询速度极慢,日常卡死.严重影响业务 ...

  5. HttpClient之EntityUtils工具类

    今天看到tttpclient-tutorial上面有这样一句话-----非常的不推荐使用EntityUtils,除非知道Entity是来自可信任的Http Server 而且还需要知道它的最大长度.文 ...

  6. 网络体系之TCP/IP模型

    TCP/IP参考模型是因特网使用的参考模型,这个体系结构在它的两个主要协议出现以后,被称为TCP/IP参考模型.该模型将网络协议分为四层:网络接口层.网络层.运输层.应用层. TCP/IP协议不是TC ...

  7. html 的一些基础操作

    花了一天学了点html语言..不记下来的话又白学了 基础中的基础格式 <!DOCTYPE html> <html> <head> <!-- 字符集的选择 ut ...

  8. 安装uWebSocketIO

    https://github.com/uNetworking/uWebSockets sudo apt-get install libuv1-dev git clone https://github. ...

  9. XenServer(服务器虚拟化平台)

    Citrix Xenserver,思杰基于Xen的虚拟化服务器.Citrix XenServer是一种全面而易于管理的服务器虚拟化平台,基于强大的 Xen Hypervisor 程序之上.Xen技术被 ...

  10. 51nod 1518 稳定多米诺覆盖(容斥+二项式反演+状压dp)

    [传送门[(http://www.51nod.com/Challenge/Problem.html#!#problemId=1518) 解题思路 直接算不好算,考虑容斥,但并不能把行和列一起加进去容斥 ...