java切图片,把1个大图切成9个小图. 代码原文:https://blog.youkuaiyun.com/coldcoding/article/details/55667037
public static void main(String[] args) {
// https://blog.youkuaiyun.com/coldcoding/article/details/55667037
//imageIO或者fileIO能够读取图像
//BufferedImage创建一个实际的图像缓冲区,可以直接操作像素
//bufferedImage.getSbuImage返回由指定矩形区域定义的子图像。
//返回的 BufferedImage 与源图像共享相同的数据数组。
String scrImageFile = "E:\\fu2.png";
String targetDir = "img";
BufferedImage img = null;
BufferedImage scrImage = null;
try {
scrImage = ImageIO.read(new File(scrImageFile));
} catch (IOException e) {
e.printStackTrace();
}
int scrHeight = scrImage.getHeight();
int divHeight = scrHeight / 3;
int scrWidth = scrImage.getWidth();
int divWidth = scrWidth / 3;
System.out.println("width " + scrWidth);