寫出TIFF圖像我嘗試下面的代碼來完成讀寫TIFF圖像的任務:閱讀和Java中
// 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)
任何想法我能如何解決這個問題?
「ImageIO.write(圖像, 」BMP「,新文件(OUTPUTFILE))」 是不僵硬書寫能夠成功地將圖像寫爲「.bmp」文件。當我將代碼更改爲「.tiff」時,它會起作用。 – user224270 2010-05-24 19:20:17
對不起...有一個小的錯字。 ImageIO.write現在應該寫出convertedImage,而不是原始圖像。 – Jeff 2010-05-24 19:24:04
謝謝傑夫。有效!你真的救了我的一天;) – user224270 2010-05-24 19:36:49