Html 在所有网络浏览器中显示 TIFF 图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2176991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:03:12  来源:igfitidea点击:

Display TIFF image in all web browser

htmlimagehtml-helpertiff

提问by ASHOK

How to handle TIFFfile in HTML pages?

如何处理HTML 页面中的TIFF文件?

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

我想在我的 HTML 页面中显示一个 TIFF 文件。

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

我曾尝试使用嵌入标签、对象 id、img 等。但我无法在 HTML 页面中显示图像 (TIFF)。

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

我没有在我的项目中使用 Java、.NET 或任何其他东西。我只使用 HTML。



UPDATE: Safari supports TIFF image loading. How can I load TIFF images in other browsers (IE, Mozilla, Firefox, etc)?

更新:Safari 支持 TIFF 图像加载。如何在其他浏览器(IE、Mozilla、Firefox 等)中加载 TIFF 图像?

I am unable to install a third party plugin or controller (like ActiveXController).

我无法安装第三方插件或控制器(如 ActiveXController)。

采纳答案by Richard Ev

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

这归结为浏览器图像支持;看起来唯一支持 tiff 的主流浏览器是 Safari:

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

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?

你从哪里得到 tiff 图像?它们是否可以以不同的格式生成?

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

如果您有一组静态图像,那么我建议您使用PaintShop Pro 之类的工具来批量转换它们,更改格式。

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.

如果这不是一个选项,那么寻找可以在浏览器中显示图像的预先编写的 Java 小程序(或其他浏览器插件)可能会有一些麻烦。

回答by roryf

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

我找到了详细介绍各种方法的资源: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.

如前所述,这在很大程度上取决于浏览器对格式的支持。在 Windows 上的 Chrome 中查看该页面未显示任何图像。

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

如果您发布已经尝试过的代码,这也会很有帮助。

回答by Pradeep Yadav

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

Tiff 图像只能直接显示在 IE 和 safari 上。不支持 chrome 和 firefox 上的 tiff 图像。您可以对图像进行编码,然后通过将编码的图像解码为其他格式将其显示在浏览器上。希望这对你有用

回答by Roberto Rodriguez

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

您可以尝试将图像从 tiff 转换为 PNG,方法如下:

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;

    }