如何找出 FreeImage 中 TIFF 图像的压缩情况?

发布于 2024-10-26 09:52:49 字数 97 浏览 1 评论 0原文

我使用 FreeImage 处理多页 TIFF 文件,有时我在 FIBITMAP 中有一个 TIFF 页面,我需要知道它的压缩情况。知道如何做到这一点吗?

I use FreeImage to work with multipage TIFF files and at some point I have a TIFF page, in a FIBITMAP and I need to know its compression. Any idea how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女情怀诗 2024-11-02 09:52:49

FreeImage 没有内置函数来显示 tiff 文件压缩方案,但是您可以使用 Exif 元数据来弄清楚(dib 是本地 FIBITMAP 变量,这是 C# 代码):

    public string GetCompressionName()
    {
        long _compression;

        if (dib.IsNull)
           throw new Exception("dib is empty - image haven't been loaded!");

        //Searching tag in metadata.
        ImageMetadata iMetadata = new ImageMetadata(dib);

        foreach (MetadataModel metadataModel in iMetadata)
        {
            if (metadataModel.ToString() == "FIMD_EXIF_MAIN")
            {
                try
                { long.TryParse(metadataModel.GetTag("Compression").ToString(), out _compression); }
                catch
                { return "Unknown"; }


                if (CompressType.ContainsKey(_compression))
                {
                    string _compressionName;
                    CompressType.TryGetValue(_compression, out _compressionName);

                    if (_compressionName != null)
                    {
                        return _compressionName;
                    }
                }
            }
        }

        return "Unknown";
    }

Dictionary<long, string> CompressType = new Dictionary<long, string>()
        { 
            {1, "Uncompressed" } ,
            {2, "CCITT modified Huffman RLE"},
            {32773, "PackBits"}, 
            {3, "CCITT3"},
            {4, "CCITT4"},
            {5, "LZW"},
            {6, "JPEG_old"},
            {7, "JPEG_new"},
            {32946, "DeflatePKZIP"},
            {8, "DeflateAdobe"},
            {9, "JBIG_85"},
            {10, "JBIG_43"},
            {11, "JPEG"},
            {12, "JPEG"},
            {32766, "RLE_NeXT"},
            {32809, "RLE_ThunderScan"},
            {32895, "RasterPadding"},
            {32896, "RLE_LW"},
            {32897, "RLE_HC"},
            {32947, "RLE_BL"},
            {34661, "JBIG"},
            {34713, "Nikon_NEF"},
            {34712,"JPEG2000"}
        };

FreeImage has no built in function to reveal the tiff file compression scheme, however you can use Exif metadata to figure that out (dib is local FIBITMAP variable, this is c# code):

    public string GetCompressionName()
    {
        long _compression;

        if (dib.IsNull)
           throw new Exception("dib is empty - image haven't been loaded!");

        //Searching tag in metadata.
        ImageMetadata iMetadata = new ImageMetadata(dib);

        foreach (MetadataModel metadataModel in iMetadata)
        {
            if (metadataModel.ToString() == "FIMD_EXIF_MAIN")
            {
                try
                { long.TryParse(metadataModel.GetTag("Compression").ToString(), out _compression); }
                catch
                { return "Unknown"; }


                if (CompressType.ContainsKey(_compression))
                {
                    string _compressionName;
                    CompressType.TryGetValue(_compression, out _compressionName);

                    if (_compressionName != null)
                    {
                        return _compressionName;
                    }
                }
            }
        }

        return "Unknown";
    }

Dictionary<long, string> CompressType = new Dictionary<long, string>()
        { 
            {1, "Uncompressed" } ,
            {2, "CCITT modified Huffman RLE"},
            {32773, "PackBits"}, 
            {3, "CCITT3"},
            {4, "CCITT4"},
            {5, "LZW"},
            {6, "JPEG_old"},
            {7, "JPEG_new"},
            {32946, "DeflatePKZIP"},
            {8, "DeflateAdobe"},
            {9, "JBIG_85"},
            {10, "JBIG_43"},
            {11, "JPEG"},
            {12, "JPEG"},
            {32766, "RLE_NeXT"},
            {32809, "RLE_ThunderScan"},
            {32895, "RasterPadding"},
            {32896, "RLE_LW"},
            {32897, "RLE_HC"},
            {32947, "RLE_BL"},
            {34661, "JBIG"},
            {34713, "Nikon_NEF"},
            {34712,"JPEG2000"}
        };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文