首页>代码>java swing开发的拼图小游戏项目>/Puzzle/src/demo/ImageCutUtil.java
package demo;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class ImageCutUtil {
	final static int NUM=25;
	public static void removeAll(File path){
		File fileImage;
		for(int i=0;i<NUM;i++){
			fileImage=new File(path,i+".jpg");
			if(fileImage.isFile())
				fileImage.delete();
			
		}
	}
	public static boolean cutImage(File sourcePath,int cutNumber,String savePath){
		try {
			System.out.println("cutNumber :"+cutNumber);
			BufferedImage source=ImageIO.read(sourcePath);
			int allWidth=source.getWidth();
			int allHeight=source.getHeight();
			int width=(int)(allWidth*1.0/cutNumber);
			int height=(int)(allHeight*1.0/cutNumber);
			System.out.println("cutNumber "+cutNumber);
			for(int i=0;i<cutNumber;i++)
				for(int j=0;j<cutNumber;j++){
					ImageIO.write(source.getSubimage(j*width, i*height, width, height),
							"jpg",new File(savePath+"\\"+(i*cutNumber+j)+".jpg"));
				}
				return true;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
}
}
最近下载更多
1112WHQ  LV7 2023年11月3日
applejack  LV1 2023年6月11日
当代大学生  LV1 2023年5月3日
huangzy  LV12 2023年4月6日
alexcheung  LV3 2022年12月17日
微信网友_5992582549164032  LV6 2022年6月15日
nikki0401  LV1 2022年3月22日
13112360  LV2 2022年1月20日
dwaddwadaw  LV1 2022年1月11日
KillerMain  LV1 2021年12月28日
最近浏览更多
2890892945  LV2 2023年12月31日
shajunming  LV2 2023年11月6日
1112WHQ  LV7 2023年11月3日
applejack  LV1 2023年6月11日
当代大学生  LV1 2023年5月3日
huangzy  LV12 2023年4月6日
win1991  LV6 2023年3月27日
alexcheung  LV3 2022年12月17日
103463  LV1 2022年12月5日
wangroot98  LV1 2022年11月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友