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();
}
}
}
}

    推荐阅读