java 对上传图片缩放剪切
一般上传图片分三步:
第一步:将原始图片上传到服务器端保存,不妨命名为src.jpg
第二步:在浏览器端将src.jpg显示出来,然后使用jQuery,对其进行“客户端剪切”。
所谓客户端剪切就是根据用户在界面中对原始图片放大,移动,剪切时,获得一些参数。
具体需要六个参数(srcWidth, srcHeight, rect.x, rect.y , rect.width, rect.height)参数。
其中,srcWidth 和srcHeight表明原始图片在客户端放大后的宽和高
rect.x和rect.y表明剪切部分相对(srcWidth, srcHeight)的起始坐标
rect.width和rect.height表示需要剪切的图片的大小。
第三步:获取第二步得到的参数,对内存中原始图片先进行预处理(按照srcWidth和srcHeight进行缩放)、剪切。
然后对预处理后的内存图像剪切,打印出来。
第一步实现比较简单,第二步需要学习jQuery,网上例子很多。我们重点讨论第三步, java切图。
1.main函数
package syj.vo;public class ImageVo { private int txt_width; private int txt_height; private int txt_top; private int txt_left; private int txt_DropWidth; private int txt_DropHeight; private float imageZoom; private String picture; public int getTxt_width() { return txt_width; } public void setTxt_width(int txtWidth) { txt_width = txtWidth; } public int getTxt_height() { return txt_height; } public void setTxt_height(int txtHeight) { txt_height = txtHeight; } public int getTxt_top() { return txt_top; } public void setTxt_top(int txtTop) { txt_top = txtTop; } public int getTxt_left() { return txt_left; } public void setTxt_left(int txtLeft) { txt_left = txtLeft; } public int getTxt_DropWidth() { return txt_DropWidth; } public void setTxt_DropWidth(int txtDropWidth) { txt_DropWidth = txtDropWidth; } public float getImageZoom() { return imageZoom; } public void setImageZoom(float imageZoom) { this.imageZoom = imageZoom; } public void setPicture(String picture) { this.picture = picture; } public String getPicture() { return picture; } public void setTxt_DropHeight(int txt_DropHeight) { this.txt_DropHeight = txt_DropHeight; } public int getTxt_DropHeight() { return txt_DropHeight; } }