首页>代码>jsp+Servlet+jcrop开发实现上传图片裁剪简单demo实例>/myupload/src/com/myupload/servlet/UploadSubImageServlet.java
package com.myupload.servlet;

import java.io.IOException;

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

import com.myupload.util.ImageUtils;

public class UploadSubImageServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String path = request.getParameter("path");
		String fileName = path.substring(path.lastIndexOf("/") + 1);
		String formatName = fileName.substring(fileName.lastIndexOf('.') + 1);
		System.out.println(path + "============" + fileName);
		ImageUtils image = null;
		
		int initWidth = Integer.parseInt(request.getParameter("initWidth"));
		int initHeight = Integer.parseInt(request.getParameter("initHeight"));
        int startX = Math.round(Float.parseFloat(request.getParameter("startX")));
        int startY = Math.round(Float.parseFloat(request.getParameter("startY")));
        int endX = Math.round(Float.parseFloat(request.getParameter("endX")));
        int endY = Math.round(Float.parseFloat(request.getParameter("endY")));
        int width = Math.round(Float.parseFloat(request.getParameter("width")));
        int height = Math.round(Float.parseFloat(request.getParameter("height")));
        System.out.println(startX + "==" + startY + "==" + endX + "==" + endY + "==" + width + "==" + height);
        
        try {
			image = ImageUtils.load(getServletContext().getRealPath("/") + path);
			//image.zoomImage(p, "e:/xxx.jpg", 500, 500, "jpg");
			image.zoomTo(initWidth, initHeight);
			image.cutTo(startX, startY, width, height);
			image.save(getServletContext().getRealPath("/") + "dealImage/" + fileName, formatName);
		} catch (IOException e) {
			e.printStackTrace();
		}
		response.sendRedirect("myupload.jsp");
	}

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

}
最近下载更多
7348449521111  LV1 2023年4月20日
zzh1  LV7 2022年11月8日
Mayoubin2001  LV21 2022年3月26日
松烟入墨2018  LV16 2020年7月13日
pharaohsprince  LV1 2020年4月23日
KING QIN  LV5 2020年3月3日
he88318799  LV16 2019年10月11日
cccnccc  LV11 2019年6月4日
IanDiane666  LV1 2019年5月31日
仪万里  LV12 2019年5月9日
最近浏览更多
颜菜菜  LV2 2023年12月23日
WASDZZ  LV13 2023年7月7日
7348449521111  LV1 2023年4月20日
itwgy001  LV2 2022年12月9日
softandroad 2022年11月7日
暂无贡献等级
zzh1  LV7 2022年11月5日
JohnAlex  LV9 2022年4月21日
Mayoubin2001  LV21 2022年3月26日
12346678912334566 2022年1月8日
暂无贡献等级
zphhhh 2022年1月8日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友