`

jQuery与Java实现图片的剪切

 
阅读更多
一 参考资料
1 jquery Jcrop 头像,logo截图 
http://terje.blog.163.com/blog/static/11924371201101311319664/
2 javascript+java截取图像,图像处理
http://www.blogjava.net/b47248054/articles/200685.html
3 js+java 截取照片中的头像
http://blog.csdn.net/dsj188/article/details/4313662
4 java+jsp 截头像图片
http://ldf2008rw.iteye.com/blog/502793
5 Java生成缩略图之Thumbnailator
http://rensanning.iteye.com/blog/1545708
Thumbnailator 是一个为Java界面更流畅的缩略图生成库。从API提供现有的图像文件和图像对象的缩略图中简化了缩略过程,两三行代码就能够从现有图片生成缩略图,且允许微调缩略图生成,同时保持了需要写入到最低限度的代码量。同时还支持根据一个目录批量生成缩略图。 http://code.google.com/p/thumbnailator/这个不错!支持!

二 解决思路
1 通过smart-upload文件上传组件将图片上传到服务器,并得到图片文件地址传递到前台的img组件显示
2 在客户端用JS获取图片X坐标,Y坐标,宽度和高度这四个参数并设置到隐藏元素.
3 java后台根据图片关键的四个参数实现图片剪切并在服务器端生成图片文件
4 通过生成图片的地址在前台展现

开发环境: XP3
开发工具: JDK1.6+MyEclipse6.5+Tomcat6

工程图片:

三 实现方式
1 选用JQuery插件:Jcrop
官方网站:http://deepliquid.com/content/Jcrop.html
项目地址:http://code.google.com/p/jcrop/
效果图片如下:

2 通过图片剪切工具类,主要代码如下:
/** 
     * 图像切割(改)     * 
     * @param srcImageFile            源图像地址
     * @param dirImageFile            新图像地址
     * @param x                       目标切片起点x坐标
     * @param y                      目标切片起点y坐标
     * @param destWidth              目标切片宽度
     * @param destHeight             目标切片高度
     */
    public static void abscut(String srcImageFile,String dirImageFile, int x, int y, int destWidth,
            int destHeight) {
        try {
            Image img;
            ImageFilter cropFilter;
            // 读取源图像
            BufferedImage bi = ImageIO.read(new File(srcImageFile));
            int srcWidth = bi.getWidth(); // 源图宽度
            int srcHeight = bi.getHeight(); // 源图高度          
            if (srcWidth >= destWidth && srcHeight >= destHeight) {
                Image image = bi.getScaledInstance(srcWidth, srcHeight,
                        Image.SCALE_DEFAULT);
                // 改进的想法:是否可用多线程加快切割速度
                // 四个参数分别为图像起点坐标和宽高
                // 即: CropImageFilter(int x,int y,int width,int height)
                cropFilter = new CropImageFilter(x, y, destWidth, destHeight);
                img = Toolkit.getDefaultToolkit().createImage(
                        new FilteredImageSource(image.getSource(), cropFilter));
                BufferedImage tag = new BufferedImage(destWidth, destHeight,
                        BufferedImage.TYPE_INT_RGB);
                Graphics g = tag.getGraphics();
                g.drawImage(img, 0, 0, null); // 绘制缩小后的图
                g.dispose();
                // 输出为文件
                ImageIO.write(tag, "JPEG", new File(dirImageFile));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


四 具体代码如下:
1 index.jsp(上传图片页面)
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">    
    <title></title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    	
	<script src="/scripts/clearFile.js" type="text/javascript"></script>
	<script type="text/javascript">
	
		/**检查图片上传类型*/		
		 function checkImgType(obj){
		 
		  var imgFile = '';	
		  //获取图片的全路径
		  var imgFilePath = getImgFullPath(obj);	 
		  var endIndex = imgFilePath.lastIndexOf("\\");
		  var lastIndex = imgFilePath.length-endIndex-1;
		  if (endIndex != -1)
		     imgFile= imgFilePath.substr(endIndex+1,lastIndex);
		  else
		  	 imgFile = imgFilePath;		
		  	
		  var tag = true;	 	  	 
		  endIndex = imgFilePath.lastIndexOf(".");			 
		  if (endIndex == -1) 
		    tag = false;
		    
		  var ImgName = imgFilePath.substr(endIndex+1,lastIndex);
		  ImgName = ImgName.toUpperCase();		  
		 
		  if (ImgName !="GIF" && ImgName !="JPG" && ImgName !="PNG" && ImgName !="BMP"){ 
		      tag=false;
		  }
		  if (!tag) {
		      alert("上传图片的文件类型必须为: *.gif,*.jpg,*.png,*.bmp,请重新选择!")
		      Upload.clear(obj);			      	 
		 	  return false;
		  }   
		  document.form1.submit();
	  }
		
		function getImgFullPath(obj) {
		    if (obj) {  
		       //ie  
		       if (window.navigator.userAgent.indexOf("MSIE") >= 1) {  
		           obj.select();  
		           return document.selection.createRange().text;  
		       }  
		       //firefox  
		       else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {  
		           if (obj.files) {  
		               return obj.files.item(0).getAsDataURL();  
		           }  
		           return obj.value;  
		       }         
		       return obj.value;  
		   }  
		} 
	</script>
	
  </head>  
  <body>
    <form name=form1 method=post enctype="multipart/form-data" action="<%=path%>/imgUpload">
    	<div style="margin-left: 35%;margin-top: 20%">
    	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >    	   
          <tr>              
               <td >&nbsp;图片上传<font color='red'>*.gif,*.jpg,*.png,*.bmp</font></td>              
           </tr>  
           <tr>   
               <td width="80%">            	
		         <input type="file" name="imgFile" id="imgFile" maxlength="160" onchange="checkImgType(this);" width="300px"/>&nbsp;	                     
		       </td>    
           </tr>               
    	</table>  
       </div>
    </form>
  </body>
</html>

2 ImgUploadServlet.java(图片上传处理类)
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ImgUploadServlet extends HttpServlet {


	private static final long serialVersionUID = 1L;
	public static final String IMGROOT = "/uploads/";
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
		String userWebAppPath = getWebAppPath();
		/**检查是否有图片上传文件夹*/
		checkImageDir(userWebAppPath);	
		
		/**图片上传的相对路径*/
		String imgUploadPath = null;
		String imgWebAppPath = null;
		/**图片后缀*/
		String imgFileExt = null;
		
		/**图片名称:以当前日期*/
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmss");
		String imgFileId = formatter.format(new Date());
		
		//图片初始化高度与宽度
		String width = null;
		String height = null;
		
		int imgWidth = 0;
		int imgHeight = 0;

		try {
			
			com.jspsmart.upload.SmartUpload smartUpload = new com.jspsmart.upload.SmartUpload();
			smartUpload.initialize(getServletConfig(), request, response);
			smartUpload.upload();
			com.jspsmart.upload.Request rqest = smartUpload.getRequest();
			
			//指定图片宽度和高度
			width = rqest.getParameter("width");
			if(null == width){
				width = "700";
			}
			height= rqest.getParameter("height");	
			if(null == height){
				height = "600";
			}
			
			imgWidth = Integer.parseInt(width);
			imgHeight = Integer.parseInt(height);
			
			
			//文件个数
			int fileCounts =  smartUpload.getFiles().getCount();	
		
			for (int i = 0; i <fileCounts; i++) {
				com.jspsmart.upload.File myFile = smartUpload.getFiles().getFile(i);
				
				if (!myFile.isMissing()) {
					
					imgFileExt = myFile.getFileExt();
					//组装图片真实名称
					imgFileId += i + System.currentTimeMillis() + "." + imgFileExt;
					
					//图片生成路径
					imgWebAppPath = userWebAppPath + imgFileId;
					
					//生成图片文件
					myFile.saveAs(imgWebAppPath);
					//图片的相对路径
					imgUploadPath = IMGROOT + imgFileId;
					
					//检查图片大小
					BufferedImage src = ImageIO.read(new File(imgWebAppPath)); // 读入文件						 
					int imgSrcWidth = src.getWidth(); // 得到源图宽							 
					//重新指定大小
					imgWidth = imgSrcWidth > imgWidth ? imgWidth : imgSrcWidth;
					
					int imgSrcHeight = src.getHeight(); // 得到源图长
					imgHeight = imgSrcHeight > imgHeight ? imgHeight : imgSrcHeight;
				
					//按照图片的设置大小生成
					ImageCut.scale(imgWebAppPath, imgWebAppPath,imgWidth,imgHeight);
					 File f = new File(imgWebAppPath);								
					 if(f.exists()){						
						 System.out.println("创建"+imgWidth+"*"+imgHeight+"图片成功");
					 }					
				}
				
			}
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
		
		String path = "/imgcrop.jsp?tag=0&oldImgPath="+imgUploadPath+"&imgFileExt="+imgFileExt+"&imgRoot="+IMGROOT+"&width="+imgWidth+"&height="+imgHeight;
		System.out.println("path: "+path);
		request.getRequestDispatcher(path).forward(request,response);
		
	}
	
	private String getWebAppPath(){
		String webAppPath = this.getServletContext().getRealPath("/");		
		String userWebAppPath = webAppPath+IMGROOT;
		return userWebAppPath;
	}

	private void checkImageDir(String userWebAppPath) {		
		 File file = new File(userWebAppPath);
		 if(!file.exists()){
			 file.mkdir();
		 }
	}
}

3 imgcrop.jsp(图片展现并剪切页面)
<%@ page language="java"  pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">    
    <title>图片剪辑</title>    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="styles/jquery.Jcrop.css" type="text/css" />
	<link rel="stylesheet" href="styles/demos.css" type="text/css" />	
	<script src="scripts/jquery.min.js"></script>
	<script src="scripts/jquery.Jcrop.js"></script>		
  </head>  
 <body STYLE='OVERFLOW:SCROLL;OVERFLOW-X:HIDDEN;OVERFLOW-Y:HIDDEN'>
 	
    <form name=form1 method=post action="<%=path%>/imgCrop">
    	
    	<table width="60%" border="0" align="center" cellpadding="0" cellspacing="0" >    	   
           <tr>    
               <td id="cropTd" style="display:none"><input type="button" value="剪切照片" id="cropButton"/></td>    
           </tr>   
           
            <tr>              
              <td id="imgTd" style="width:${param.width}px;height:${param.height}px;" align="center" style="padding-top:5px;">    
              	 <c:choose>
              	 	<c:when test="${param.tag eq 0}">
              	 		<img  src="<%=path%>${param.oldImgPath}" id="imgCrop" name="imgCrop" border="0" />     
              	 	</c:when>
              	 	<c:when test="${param.tag eq 1}">
              	 		<img  src="<%=path%>${param.imgName}" id="imgCrop" name="imgCrop" border="0" />    
              	 	</c:when>
              	 </c:choose>  
            </td>               
           </tr> 
             
            <tr>  
               <td>
               	     <label>X1 <input type="text" size="4" id="labelX" name="labelX" /></label>
					<label>Y1 <input type="text" size="4" id="labelY" name="labelY" /></label>
					<label>X2 <input type="text" size="4" id="labelX2" name="labelX2" /></label>
					<label>Y2 <input type="text" size="4" id="labelY2" name="labelY2" /></label>
					<label>W <input type="text" size="4" id="labelW" name="labelW" /></label>
					<label>H <input type="text" size="4" id="labelH" name="labelH" /></label>
               </td>    
           </tr>
           
            <tr>  
               <td  colspan="2"><a href="index.jsp">返回上传图片</a></td>    
           </tr>            
     </table>
    
	<input type="hidden"  id="x" name="x" />
	<input type="hidden"  id="y" name="y" />
	<input type="hidden"  id="x2" name="x2" />
	<input type="hidden"  id="y2" name="y2" />
	<input type="hidden"  id="w" name="w" />
	<input type="hidden"  id="h" name="h" />  
	
	<!-- 源图片宽度和高度 -->
	<input type="hidden"  id="width" name="width" value="${param.width}"/>  
	<input type="hidden"  id="height" name="height" value="${param.height}"/>
	<input type="hidden"  id="oldImgPath" name="oldImgPath" value="${param.oldImgPath}"/>  
	<input type="hidden"  id="imgRoot" name="imgRoot" value="${param.imgRoot}"/>	
	<input type="hidden"  id="imgFileExt" name="imgFileExt" value="${param.imgFileExt}"/>	
	
    </form>
  </body>
</html>
<script type="text/javascript">

	jQuery(document).ready(function(){		
	
		
		jQuery('#imgCrop').Jcrop({
			onChange: showCoords,
			onSelect: showCoords
		});	
		
		jQuery('#cropButton').click(function(){
			    var x = jQuery("#x").val();
				var y = jQuery("#y").val();
				var w = jQuery("#w").val();
				var h = jQuery("#h").val();			
				
				if(w == 0 || h == 0 ){
					alert("您还没有选择图片的剪切区域,不能进行剪切图片!");
					return;
				}	
				alert("你要剪切图片的X坐标: "+x + ",Y坐标: " + y + ",剪切图片的宽度: " + w + ",高度:" + h );
				if(confirm("确定按照当前大小剪切图片吗")){				
					document.form1.submit();
				}
		 });
		
	
	});
	
	function showCoords(c)
	{
		jQuery('#x').val(c.x);
		jQuery('#y').val(c.y);
		jQuery('#x2').val(c.x2);
		jQuery('#y2').val(c.y2);
		jQuery('#w').val(c.w);
		jQuery('#h').val(c.h);	
		
		jQuery('#labelX').val(c.x);
		jQuery('#labelY').val(c.y);
		jQuery('#labelX2').val(c.x2);
		jQuery('#labelY2').val(c.y2);
		jQuery('#labelW').val(c.w);
		jQuery('#labelH').val(c.h);	
		
		//显示剪切按键
		jQuery('#cropTd').css("display","");
				
	}
</script>

4 ImgCropServlet.java(执行图片剪切类)
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ImgCropServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		System.out.println("x: " + request.getParameter("x") + "," + request.getParameter("y") + "," + request.getParameter("w") + "," + request.getParameter("h"));

		// 用户经过剪辑后的图片的大小
		Integer x = Integer.parseInt(request.getParameter("x"));
		Integer y = Integer.parseInt(request.getParameter("y"));
		Integer w = Integer.parseInt(request.getParameter("w"));
		Integer h = Integer.parseInt(request.getParameter("h"));
		
		//获取原显示图片路径
		String oldImgPath = request.getParameter("oldImgPath");
		//图片后缀
		String imgFileExt = request.getParameter("imgFileExt");
		String imgRoot =  request.getParameter("imgRoot");
		
		Integer width = Integer.parseInt(request.getParameter("width"));
		Integer height = Integer.parseInt(request.getParameter("height"));
		
		//WEB应用程序根路径
		String webAppPath = getServletContext().getRealPath("/");
		
		/**图片名称:以当前日期*/
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmss");
		String imgFileId = formatter.format(new Date());
		String imgName =  imgRoot + imgFileId + System.currentTimeMillis() + "." + imgFileExt;			
		//组装图片真实名称
		String createImgPath = webAppPath + imgName;
		
		//之前上传的图片路径
		webAppPath += oldImgPath;
		
		System.out.println("原图片路径: " + webAppPath + ",新图片路径: " + createImgPath);
		
		//进行剪切图片操作
		ImageCut.abscut(webAppPath, createImgPath, x,y,w, h);
		
		 File f = new File(createImgPath);								
		 if(f.exists()){						
			 System.out.println("剪切图片大小: "+w+"*"+h+"图片成功!");
		 }	
		 
		String path = "/imgcrop.jsp?tag=1&oldImgPath="+oldImgPath+"&imgFileExt="+imgFileExt+"&imgRoot="+imgRoot + "&imgName="+imgName+"&height=" + height + "&width=" + width;
		System.out.println("imgCrop: " + path);
		request.getRequestDispatcher(path).forward(request,response);
	}

}

5 ImageCut.java(图片剪切工具类)
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.Graphics;
import java.awt.color.ColorSpace;
import javax.imageio.ImageIO;

public class ImageCut {
	
	/** 
     * 图像切割(改)     * 
     * @param srcImageFile            源图像地址
     * @param dirImageFile            新图像地址
     * @param x                       目标切片起点x坐标
     * @param y                      目标切片起点y坐标
     * @param destWidth              目标切片宽度
     * @param destHeight             目标切片高度
     */
    public static void abscut(String srcImageFile,String dirImageFile, int x, int y, int destWidth,
            int destHeight) {
        try {
            Image img;
            ImageFilter cropFilter;
            // 读取源图像
            BufferedImage bi = ImageIO.read(new File(srcImageFile));
            int srcWidth = bi.getWidth(); // 源图宽度
            int srcHeight = bi.getHeight(); // 源图高度          
            if (srcWidth >= destWidth && srcHeight >= destHeight) {
                Image image = bi.getScaledInstance(srcWidth, srcHeight,
                        Image.SCALE_DEFAULT);
                // 改进的想法:是否可用多线程加快切割速度
                // 四个参数分别为图像起点坐标和宽高
                // 即: CropImageFilter(int x,int y,int width,int height)
                cropFilter = new CropImageFilter(x, y, destWidth, destHeight);
                img = Toolkit.getDefaultToolkit().createImage(
                        new FilteredImageSource(image.getSource(), cropFilter));
                BufferedImage tag = new BufferedImage(destWidth, destHeight,
                        BufferedImage.TYPE_INT_RGB);
                Graphics g = tag.getGraphics();
                g.drawImage(img, 0, 0, null); // 绘制缩小后的图
                g.dispose();
                // 输出为文件
                ImageIO.write(tag, "JPEG", new File(dirImageFile));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    
	/**
	 * 缩放图像
	 * 
	 * @param srcImageFile       源图像文件地址
	 * @param result             缩放后的图像地址
	 * @param scale              缩放比例
	 * @param flag               缩放选择:true 放大; false 缩小;
	 */
	public static void scale(String srcImageFile, String result, int scale,
			boolean flag) {
		try {
			BufferedImage src = ImageIO.read(new File(srcImageFile)); // 读入文件
			int width = src.getWidth(); // 得到源图宽
			int height = src.getHeight(); // 得到源图长
			if (flag) {
				// 放大
				width = width * scale;
				height = height * scale;
			} else {
				// 缩小
				width = width / scale;
				height = height / scale;
			}
			Image image = src.getScaledInstance(width, height,Image.SCALE_DEFAULT);
			BufferedImage tag = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
			Graphics g = tag.getGraphics();
			g.drawImage(image, 0, 0, null); // 绘制缩小后的图
			g.dispose();
			ImageIO.write(tag, "JPEG", new File(result));// 输出到文件流
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 重新生成按指定宽度和高度的图像
	 * @param srcImageFile       源图像文件地址
	 * @param result             新的图像地址
	 * @param _width             设置新的图像宽度
	 * @param _height            设置新的图像高度
	 */
	public static void scale(String srcImageFile, String result, int _width,int _height) {		
		scale(srcImageFile,result,_width,_height,0,0);
	}
	
	public static void scale(String srcImageFile, String result, int _width,int _height,int x,int y) {
		try {
			
			BufferedImage src = ImageIO.read(new File(srcImageFile)); // 读入文件
			
			int width = src.getWidth(); // 得到源图宽
			int height = src.getHeight(); // 得到源图长
			
			if (width > _width) {
				 width = _width;
			}
			if (height > _height) {
				height = _height;
			}			
			Image image = src.getScaledInstance(width, height,Image.SCALE_DEFAULT);
			BufferedImage tag = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
			Graphics g = tag.getGraphics();
			g.drawImage(image, x, y, null); // 绘制缩小后的图
			g.dispose();			
			ImageIO.write(tag, "JPEG", new File(result));// 输出到文件流
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 图像类型转换 GIF->JPG GIF->PNG PNG->JPG PNG->GIF(X)
	 */
	public static void convert(String source, String result) {
		try {
			File f = new File(source);
			f.canRead();
			f.canWrite();
			BufferedImage src = ImageIO.read(f);
			ImageIO.write(src, "JPG", new File(result));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 彩色转为黑白
	 * 
	 * @param source
	 * @param result
	 */
	public static void gray(String source, String result) {
		try {
			BufferedImage src = ImageIO.read(new File(source));
			ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
			ColorConvertOp op = new ColorConvertOp(cs, null);
			src = op.filter(src, null);
			ImageIO.write(src, "JPEG", new File(result));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}	
}
  • 大小: 50.6 KB
  • 大小: 25.2 KB
分享到:
评论
28 楼 199310290808 2015-12-01  
[u][u][u][u][u][u][u][u][u][u]46545646[/u][/u][/u][/u][/u][/u][/u][/u][/u][/u]
27 楼 jialadykiller 2015-08-18  
非常感谢
26 楼 当里个当1 2015-07-22  
学习了,非常感谢
25 楼 xiajinqian 2015-01-29  
很不错,谢谢!
24 楼 913545731lin 2014-12-22  
为什么不能下载源码?
23 楼 静坛使者 2014-09-28  
hezhoujun 写道
解决了我的难题,谢谢你!想加你的qq成为好友

我可以也加嘛?真的挺好的 代码
22 楼 xiaocaon 2014-09-10  
21 楼 zuoguiyefengliu 2014-09-03  
abscut方法截取有问题,右边生成黑色边框如何解决??
20 楼 u010272442 2014-06-24  
那个,问一下,smart-upload包干啥的啊?
19 楼 大大粒 2014-05-20  
你好,请问我想限制选择框的宽和高,请问在哪里限制?
18 楼 hezhoujun 2014-04-02  
解决了我的难题,谢谢你!想加你的qq成为好友
17 楼 1807151593 2013-06-14  
真心谢谢~~~
16 楼 liuzidong 2012-11-29  
工程在附件中呀,直接下载就是了,文章上面也有直接的代码呀
15 楼 majingxia989 2012-11-27  
楼主能分享一下工程吗?愁死我了
14 楼 majingxia989 2012-11-27  
楼主能分享一下工程吗
13 楼 tiankong6622 2012-09-19  
12 楼 king520 2012-08-22  
学习下! 
11 楼 huakaihualuo1223 2012-08-18  
liuzidong 写道
1 我是用的是:0.9.8的版本获取的
2 你可以在js中作个处理吧

多谢楼主,我在java里把小数部分舍弃了,基本没多少影响
10 楼 liuzidong 2012-08-17  
1 我是用的是:0.9.8的版本获取的
2 你可以在js中作个处理吧
9 楼 huakaihualuo1223 2012-08-15  
liuzidong 写道
Jcrop插件获取的只是整数!具体看它的实现吧!

最新jcrop插件确实可以获得小数,我是做项目的时候遇到了这个问题,出现了异常,你可以试一下截图

相关推荐

    JAVA实现的图片剪切预览

    JAVA实现的图片剪切预览,使用JQUERY控件实现图片的页面裁剪,然后通过JAVA后台实现对图片的剪切处理

    头像剪切上传jquery+java源码

    头像剪切上传jquery+java源码,uploadimage.jsp为图片上传页面,简单方便实用

    js+jquery+java实现的头像上传和裁剪

    js+jquery+java实现的头像上传和裁剪,界面仿百度头像上传样式,完美兼容各种浏览器,集成java上传技术+java图像处理+js剪切图片效果+jquery无刷新上传文件

    JQuery 及插件实现图片剪切分割上传服务器

    最近做一个项目的图像上传功能,这个功能就是类似与大型网站的图像上传功能。上传切割主要是相对于起点的四个偏移量,left、top、width、height值,然后在后台进行切割显示给会员。

    jQuery-photoClip-master 图片上传剪切

    jQuery-photoClip-master 图片商城剪切,jq,js web开发

    jquery上传头像图片剪切

    jquery上传头像进行图片剪切,尺寸分别为180px*180px/128px*128px/64px*64px

    struts2加jquery加Jcrop实现头像剪切上传

    自己通过ajaxfileupload.js结合struts2实现图片上传文件,并通过jcrop和java图像处理功能实现了图片剪切的功能。该功能效果和新浪QQ的头像上传功能效果一样,在ie下可以正常使用 火狐下更换图片时效果样式会走形

    java上传剪切头像

    java jquery做得一个上传头像的例子 可以剪切头像 设置剪切大小 指定上传路径等

    jquery.Jcrop结合JAVA后台实现图片裁剪上传实例

    本文介绍了头像裁剪上传功能,用到的技术有 jQuery,springmvc,裁剪插件用的是jcrop(中间遇到很多坑,最终跨越)。 图片上传步骤: 1.用户选择图片 2.将图片传入后台:用户选择图片的时候选择的是各种各样的,...

    头像上传和裁剪

    js+jquery+java实现的头像上传和裁剪,界面仿百度头像上传样式,完美兼容各种浏览器,集成java上传技术+java图像处理+js剪切图片效果+jquery无刷新上传文件

    Java JDK 7学习笔记(国内第一本Java 7,前期版本累计销量5万册)

    所属分类:计算机 &gt; 软件与程序设计 &gt; JAVA(J#) &gt; Java 编辑推荐   Jworld@TW技术论坛版主,Java权威技术顾问与专业讲师,Java畅销书作者——林信良全新力作。  国内第一本Java 7,前期版本累计销量5万册。  ...

    xheditor-1.1.14

    方法2:利用xhEditor提供的jQuery插件接口来实现对特定textarea的初始化和传递参数,例: $('#elm1').xheditor(); 或者 $('#elm1').xheditor({tools:'mini'}); 特别说明:两种初始化方法只能选择其中一种使用,如果...

    RichFilemanager:开源文件管理器。 最新PHP,Java,ASHX,ASP,NodeJs和Python 3 Flask。 欢迎捐款!-python source file

    剪贴板功能:复制,剪切,粘贴,清除 可选的文件和文件夹支持(鼠标拖动和Ctrl键) 对选定文件和文件夹的多种操作支持:移动,删除,下载 之前和之后回调函数的某些操作 双击或单击设置以打开文件和文件夹 延迟加载...

    javascript常用函数(1)

    1、 调整图片大小,不走形(FF IE 兼容)/ 剪切图片(overflow:hidden) 2、 控制textarea区域文字数量 3、 点击显示新窗口 4、 input框自动随内容自动变长 5、 添加收藏夹 6、 设置首页 7、 Jquery + Ajax ...

Global site tag (gtag.js) - Google Analytics