package com.komlin.modular.test;
import com.komlin.component.utils.ImageCutterUtil;
import com.komlin.component.utils.ImageTools;
import com.komlin.component.utils.SpringContextUtils;
import com.komlin.modular.device.model.service.DeviceService;
import com.komlin.modular.work.model.entity.TbTraceRecord;
import com.komlin.modular.work.model.service.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.*;
/**
* Created by Administrator on 2017/8/7.
*/
public class JavaTest{
public static void main(String[] args) throws InterruptedException {
String sourcePath = "E:\\apache-tomcat-7.0.78\\webapps\\QRcode\\file\\draw\\gift\\668b3d33548347388e526f0b234a27d8.jpg";
try {
File file = new File(sourcePath);
BufferedImage image = ImageIO.read(file);
// 起始坐标,剪切大小
int x = 0;
int y = 0;
double destWidth = image.getWidth();
double destHeight = image.getHeight();
System.out.println(destWidth + " " + destHeight);
//剪切大小
int width = (int) Math.round(destWidth/2);
int height = (int)Math.round(destHeight/2);
if (width < 1 || height < 1) {
throw new Exception("图片过小,不可切割!");
}
for (int i = 0;i < 2; i++) {
y = 0;
for (int j = 0; j < 2; j++) {
String sourcePath2 = "E:\\apache-tomcat-7.0.78\\webapps\\QRcode\\file\\draw\\gift\\" + i + j + ".jpg";
File destFile = new File(sourcePath2);
ImageCutterUtil.cutImage(file, destFile, x, y, width, height);
y += height;
System.out.println(x + " " + y);
System.out.println(width + " " + height);
if (destHeight - y + height < 1e-7) {
y = (int)destHeight - height;
}
}
x += width;
if (destWidth - x + width < 1e-7) {
x = (int)destWidth - width;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}