在Java中读取和写出TIFF图像
我尝试了以下代码来完成读取和写入tiff图像的任务:
// Define the source and destination file names.
String inputFile = /images/FarmHouse.tif
String outputFile = /images/FarmHouse.bmp
// Load the input image.
RenderedOp src = JAI.create("fileload", inputFile);
// Encode the file as a BMP image.
FileOutputStream stream =
new FileOutputStream(outputFile);
JAI.create("encode", src, stream, BMP, null);
// Store the image in the BMP format.
JAI.create("filestore", src, outputFile, BMP, null);
但是,当我运行代码时,我收到以下错误消息:
Caused by: java.lang.IllegalArgumentException: Only images with either 1 or 3 bands
can be written out as BMP files.
at com.sun.media.jai.codecimpl.BMPImageEncoder.encode(BMPImageEncoder.java:123)
at com.sun.media.jai.opimage.EncodeRIF.create(EncodeRIF.java:79)
任何想法,我怎么能解决这个问题?