java将多张图片合成一张tif图片
public static void many2one(List bookFilePaths, String toPath,String distFileName) {
if (bookFilePaths != null && bookFilePaths.size() > 0) {
File[] files = new File[bookFilePaths.size()];
for(int i = 0;
i < bookFilePaths.size();
i++){
files[i] =new File(bookFilePaths.get(i));
}
if (files != null && files.length > 0) {
try {
ArrayList pages = new ArrayList(files.length - 1);
FileSeekableStream[] stream = new FileSeekableStream[files.length];
for (int i = 0;
i < files.length;
i++) {
stream[i] = new FileSeekableStream(
files[i].getCanonicalPath());
}
ParameterBlock pb = (new ParameterBlock());
PlanarImage firstPage = JAI.create("stream", stream[0]);
for (int i = 1;
i < files.length;
i++) {
PlanarImage page = JAI.create("stream", stream[i]);
pages.add(page);
}
TIFFEncodeParam param = new TIFFEncodeParam();
File f = new File(toPath);
if(!f.exists()){
f.mkdirs();
}
OutputStream os = new FileOutputStream(toPath + File.separator+ distFileName);
ImageEncoder enc = ImageCodec.createImageEncoder("tiff",
os, param);
param.setExtraImages(pages.iterator());
enc.encode(firstPage);
for (int i = 0;
i < files.length;
i++) {
stream[i].close();
if(files[i].isFile()&&files[i].exists()){
files[i].delete();
}
}
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
推荐阅读
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- 即将到手三百万
- 事件代理
- 思友人
- Java|Java OpenCV图像处理之SIFT角点检测详解
- java中如何实现重建二叉树
- 数组常用方法一
- 【Hadoop踩雷】Mac下安装Hadoop3以及Java版本问题
- 20210307《挑战赛怂人胆》【能量将帅挑战赛(01)】
- Java|Java基础——数组