Tôi đã thử các mã sau để hoàn thành nhiệm vụ đọc và viết tiff hình ảnh:Đọc và Viết ra hình ảnh TIFF trong 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);
Tuy nhiên, khi tôi chạy mã, tôi nhận được thông báo lỗi sau:
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)
Bất kỳ ý tưởng nào về cách giải quyết vấn đề này?
"ImageIO.write (hình ảnh, "bmp", File mới (outputFile))" là cứng không viết có thể ghi thành công hình ảnh dưới dạng tệp ".bmp". khi tôi thay đổi mã thành ".tiff" thay vào đó, nó sẽ hoạt động. – user224270
xin lỗi ... có một lỗi đánh máy nhỏ. ImageIO.write giờ đây sẽ viết ra hình ảnh đã chuyển đổi, chứ không phải hình ảnh gốc. – Jeff
Cảm ơn Jeff. nó đã làm việc! bạn thực sự đã cứu ngày của tôi;) – user224270