如何在所有浏览器中显示 TIFF 图像?

如何处理 HTML 页面中的 TIFF图像?

我尝试过使用嵌入标记、对象 id、 img 等。但是,我无法在 HTML 页面中显示 TIFF 图像。

在我的项目中,我没有使用 Java、 .NET 或任何其他替代品。

更新: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _?

223175 次浏览

This comes down to browser image support; it looks like the only mainstream browser that supports tiff is Safari:

http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support

Where are you getting the tiff images from? Is it possible for them to be generated in a different format?

If you have a static set of images then I'd recommend using something like PaintShop Pro to batch convert them, changing the format.

If this isn't an option then there might be some mileage in looking for a pre-written Java applet (or another browser plugin) that can display the images in the browser.

I found this resource that details the various methods: How to embed TIFF files in HTML documents

As mentioned, it will very much depend on browser support for the format. Viewing that page in Chrome on Windows didn't display any of the images.

It would also be helpful if you posted the code you've tried already.

Tiff images can be displayed directly onto IE and safari only.. no support of tiff images on chrome and firefox. you can encode the image and then display it on browser by decoding the encoded image to some other format. Hope this works for you

You can try converting your image from tiff to PNG, here is how to do it:

import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.ImageEncoder;
import com.sun.media.jai.codec.PNGEncodeParam;
import com.sun.media.jai.codec.TIFFDecodeParam;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javaxt.io.Image;


public class ImgConvTiffToPng {
 

public static byte[] convert(byte[] tiff) throws Exception {


byte[] out = new byte[0];
InputStream inputStream = new ByteArrayInputStream(tiff);


TIFFDecodeParam param = null;


ImageDecoder dec = ImageCodec.createImageDecoder("tiff", inputStream, param);
RenderedImage op = dec.decodeAsRenderedImage(0);


ByteArrayOutputStream outputStream = new ByteArrayOutputStream();


PNGEncodeParam jpgparam = null;
ImageEncoder en = ImageCodec.createImageEncoder("png", outputStream, jpgparam);
en.encode(op);
outputStream = (ByteArrayOutputStream) en.getOutputStream();
out = outputStream.toByteArray();
outputStream.flush();
outputStream.close();


return out;


}
}