我不知道如何处理TIFF图像,但我无法使用直接Java标准ImageIO库来读取或写入任何图像.有什么想法吗?
谢谢.
最近我在尝试显示图像文件时遇到问题.不幸的是,图像格式是TIFF格式,主要的网络浏览器不支持(因为我知道只有Safari支持这种格式).由于某些限制,我必须将此格式转换为主浏览器支持的其他格式.但是,当我尝试转换格式时,它给我带来了很多问题.
我在网上搜索过,虽然在这个链接中发布了类似的问题如何在Java中将TIF转换为PNG?"但我不能得到它提出的结果..
因此,我再次提出这个问题,希望能得到更好的解释和指导.
在完成提议的解决方案时,我遇到的问题很少:
1)根据Jonathan Feinberg提出的答案,需要安装JAI和JAI/ImageIO.但是,在我安装了它们之后,我仍然无法在Netbean 7.2中导入该文件.NetBean 7.2仍然建议导入默认的imageIO库.
2)当我使用默认的ImageIO库Read方法时,它将返回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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个Grails应用程序,它可以显示TIFF文件和其他图像的预览.
这些图像是从SOAP服务构造的,它为我提供了图像的字节.在一个服务方法中,我取byte [],从中构造一个ByteArrayInputStream,然后从中创建一个BufferedImage.
def inputStream = new ByteArrayInputStream(bytes)
BufferedImage originalImage = ImageIO.read(inputStream)
ImageIO.write(originalImage, 'png', response.outputStream)
Run Code Online (Sandbox Code Playgroud)
对于JPG,我可以轻松地将图像作为img标记的src流式传输到浏览器.但是,我需要将图像转换为其他格式(最好是JPG或PNG),以使它们成为标记的src.
我知道我需要JAI才能读取TIFF文件.jai_core.jar,jai_codec.jar文件在我的classpath中.事实上,因为我在Mac OSX上,它们是自动安装的.但是,当我运行grails应用程序并尝试从SOAP服务接收的字节构造TIFF图像时,我收到此错误:
| Error 2013-06-18 15:23:38,135 [http-bio-8080-exec-10] ERROR errors.GrailsExceptionResolver - IllegalArgumentException occurred when processing request: [GET] /BDMPlugin/BDMPlugin/displayImageFromRef - parameters:
pageRef: 28:22072FBCA0A8889D9C041D76A588BCF4DCB40376A23B5FD5C301378C8E66EB9F4933A5DFCA46365F927D9E91B337B6E1E980FB4406644801
type: TIFF
im == null!. Stacktrace follows:
Message: im == null!
Line | Method
->> 1457 | write in javax.imageio.ImageIO
- - - - - - - - - - - - - - - - - - - …Run Code Online (Sandbox Code Playgroud)