Jquery Jcrop 插件使用方法
2011-09-22 17:32
615 查看
1.下载最新的Jcrop文件。
http://deepliquid.com/content/Jcrop.html
这里的top、left、width、height都可以直接用Jcrop里获取到。 在Jcrop的“Basic Handler”这个demo里面,相应的X1、Y1、W、H这四个参数,用request可以得到这些值。
转载自:/article/4404525.html
http://deepliquid.com/content/Jcrop.html
public class Utils { public static String getExtension(File f) { return (f != null) ? getExtension(f.getName()) : ""; } public static String getExtension(String filename) { return getExtension(filename, ""); } public static String getExtension(String filename, String defExt) { if ((filename != null) && (filename.length() > 0)) { int i = filename.lastIndexOf('.'); if ((i >-1) && (i < (filename.length() - 1))) { return filename.substring(i + 1); } } return defExt; } public static String trimExtension(String filename) { if ((filename != null) && (filename.length() > 0)) { int i = filename.lastIndexOf('.'); if ((i >-1) && (i < (filename.length()))) { return filename.substring(0, i); } } return filename; } }
public class SaveImage{ /** * 保存图片 * @param img 原图路径 * @param dest 目标图路径 * @param top 选择框的左边y坐标 * @param left 选择框的左边x坐标 * @param width 选择框宽度 * @param height 选择框高度 * @return * @throws IOException */ public static boolean saveImage(File img, String dest, int top, int left, int width, int height) throws IOException { File fileDest = new File(dest); if(!fileDest.getParentFile().exists()) fileDest.getParentFile().mkdirs(); String ext = Utils.getExtension(dest).toLowerCase(); BufferedImage bi = (BufferedImage)ImageIO.read(img); height = Math.min(height, bi.getHeight()); width = Math.min(width, bi.getWidth()); if(height <= 0) height = bi.getHeight(); if(width <= 0) width = bi.getWidth(); top = Math.min(Math.max(0, top), bi.getHeight()-height); left = Math.min(Math.max(0, left), bi.getWidth()-width); BufferedImage bi_cropper = bi.getSubimage(left, top, width, height); return ImageIO.write(bi_cropper, ext.equals("png")?"png":"jpeg", fileDest); } public static void main(String[] args) { try { System.out.println(saveImage(new File("E:\\JavaWork\\pic\\WebRoot\\css\\flowers.jpg"),"E:\\JavaWork\\pic\\WebRoot\\css\\flowers1.jpg",106,87,289,217)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
这里的top、left、width、height都可以直接用Jcrop里获取到。 在Jcrop的“Basic Handler”这个demo里面,相应的X1、Y1、W、H这四个参数,用request可以得到这些值。
转载自:/article/4404525.html
相关文章推荐
- jQuery jcrop插件截图使用方法
- jQuery jcrop插件截图使用方法
- jQuery jcrop插件截图使用方法
- Jquery Jcrop 插件java的使用方法 包括图片保存类
- jQuery jcrop插件截图使用方法
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- jquery分页插件jquery.pagination.js使用方法解析
- jquery插件lazyload.js延迟加载图片的使用方法
- jQuery.raty评分插件使用方法
- jquery插件jTimer(jquery定时器)使用方法
- Jquery 模板插件 jquery.tmpl.js 的使用方法(2):嵌套each循环,temp调用(使用预编译的模板缓存)
- jquery编辑插件tinyMCE的使用方法
- Coin Slider jQuery插件使用方法
- 使用jQuery插件时避免重复引入jquery.js文件(jQuery 重复加载错误以及修复方法)
- 使用jquery插件报错:TypeError:$.browser is undefined的解决方法
- AMD异步模块定义介绍和Require.js中使用jQuery及jQuery插件的方法
- jQuery插件的使用方法
- jQuery的DataTables插件的使用方法
- 使用jquery插件layer代替window.confirm方法
- 【转】jQuery列表拖动排列-jquery list dragsort插件参数和使用方法