Jquery Jcrop 插件java的使用方法 包括图片保存类
来源:互联网 发布:centos安装内核开发包 编辑:程序博客网 时间:2024/06/06 14:16
1。下载最新的Jcrop文件。
http://deepliquid.com/content/Jcrop.html
里面有demo文件,可以直接看.但要实现剪切功能还需要类来支持。默认的是PHP的。
2。Utils类
- 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;
- }
- }
这个类主要是用来获取文件的扩展名。
3。SaveImges类
- 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可以得到这些值。
- Jquery Jcrop 插件java的使用方法 包括图片保存类
- 使用jquery jcrop插件进行图片的截取与保存
- 使用jquery jcrop插件进行图片的截取与保存
- 使用jquery jcrop插件进行图片的截取与保存
- jQuery jcrop插件截图使用方法
- jQuery jcrop插件截图使用方法
- jQuery jcrop插件截图使用方法
- jQuery图片剪裁插件 Jcrop
- jquery插件图片裁剪jcrop
- jQuery图片剪裁插件 Jcrop
- jQuery 上传头像插件Jcrop的实例
- 图片裁剪插件Jcrop.js的使用
- php+jquery+Jcrop实现上传-截取-保存图片功能
- jquery+Jcrop+servlet图片上传裁剪选择保存实例
- 关于jcrop图片裁剪插件更换不了图片的问题
- java实现图片处理之Jcrop 图像裁剪插件
- jQuery 图像裁剪插件Jcrop
- 图片裁剪插件jcrop用法
- Cannot debug project unless a host application is defined
- java发邮件(带附件)
- VC ++链接库(三)非MFC动态库
- 由mysql-安装版 制作 mysql-免安装版
- 杭电 1007
- Jquery Jcrop 插件java的使用方法 包括图片保存类
- 杭电 1008
- 杭电 1009
- 在Win Server2003中SQL2005连接端口1433总是失败
- 杭电 1010
- DSG realsync 表空间映射
- JDK卸载
- 杭电 1011
- 杭电 1012