最近我在尝试显示图像文件时遇到了问题。不幸的是,图像格式是主要网络浏览器不支持的 TIFF 格式(我知道只有 Safari 支持这种格式)。由于某些限制,我必须将此格式转换为主流浏览器支持的其他格式。但是,当我尝试转换格式时,它给我带来了很多问题。
我在网上搜索过,虽然在这个链接中发布了类似的问题How do I convert a TIF to PNG in Java? “但我不能得到它建议的结果..
因此,我再次提出这个问题,希望大家能得到更好的解释和指导。
在解决建议的解决方案过程中,我遇到的问题很少:
1)根据Jonathan Feinberg提出的答案,需要安装JAI和JAI/ImageIO。但是,在我安装了它们之后,我仍然无法在 Netbean 7.2 中导入文件。NetBean 7.2 仍然建议导入默认 imageIO 库。
2) 当我使用默认 ImageIO 库读取方法时,它将返回 NULL 值,我无法继续进行。
3)我也尝试了其他方法,例如使用 BufferedOutputStream 方法将 TIFF 文件转换为 BIN 文件,但结果文件大于 11 MB,太大而无法加载,最终加载失败。
if (this.selectedDO != null) {
String tempDO = this.selectedDO.DONo;
String inPath = "J:\\" + tempDO + ".TIF";
String otPath = "J:\\" + tempDO + ".bin";
File opFile = new File(otPath);
File inFile = new File(inPath);
BufferedInputStream input = null;
BufferedOutputStream output = null;
try {
input = new BufferedInputStream(new FileInputStream(inPath), DEFAULT_BUFFER_SIZE);
output = new BufferedOutputStream(new FileOutputStream(otPath), DEFAULT_BUFFER_SIZE);
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
} finally {
try {
output.flush();
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
因此,希望能得到大家的帮助和建议,以便我可以将 TIFF 格式转换为其他格式,例如 JPEG/PNG。