Display TIFF image in all web browser

2019-01-01 13:10发布

How to handle TIFF file in HTML pages?

I want to display a TIFF file in my HTML page.

I have tried using embedded tag, object id, img, etc. But I am unable to display the image (TIFF) in the HTML page.

I am not using Java, .NET or any other thing in my project. I am using HTML only.

Hi all,

To the above question, yesterday i got solution. i.e safari able to support TIFF image loading.

What should i do to load TIFF image in the remaining unsupported browser(IE, Mozilla, Firefox, etc)

i am unable to install third party installer or controller(like ActiveXController).

please give your valuable suggestion to this.

Thanks in Advance.

5条回答
裙下三千臣
2楼-- · 2019-01-01 14:02

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;

    }
查看更多
美炸的是我
3楼-- · 2019-01-01 14:04

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.

查看更多
笑指拈花
4楼-- · 2019-01-01 14:05

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.

查看更多
旧人旧事旧时光
5楼-- · 2019-01-01 14:09

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

查看更多
孤独总比滥情好
6楼-- · 2019-01-01 14:11

I can show tiff image in all browser.
The ie browser by default show tiff images but firefox and chrome and other browser you should convert the tiff image from img html tag to canvas tag. bottom links do this convert. please view bottom links demos:
https://github.com/rasouliali/TiffViewer

查看更多
登录 后发表回答