【发布时间】:2013-03-03 23:12:44
【问题描述】:
最近我在尝试显示图像文件时遇到了问题。不幸的是,图像格式是主要网络浏览器不支持的 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。
【问题讨论】:
-
看看 ImageMagic (imagemagick.org/script/index.php)。这是 ImageMagic 的 java 接口 (jmagick.org/index.html)
-
是不是和link中提出的ImageMagick类似,我用ImageMagick尝试了那个帖子中提出的方法,但是到
ConvertCmd convert = new ConvertCmd();时却失败了