阅读TIFF文件的尺寸和分辨率,而不先加载它 [英] Read a tiff file's dimension and resolution without loading it first

查看:754
本文介绍了阅读TIFF文件的尺寸和分辨率,而不先加载它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有第一装载它利用像下面的代码阅读一个TIFF文件的尺寸(宽度和高度)和分辨率(水平和垂直)到存储器中。这是一个很大的文件速度太慢,我也不需要操纵它们。

How to read a tiff file's dimension (width and height) and resolution (horizontal and vertical) without first loading it into memory by using code like the following. It is too slow for big files and I don't need to manipulate them.

Image tif = Image.FromFile(@"C:\large_size.tif");
float width = tif.PhysicalDimension.Width;
float height = tif.PhysicalDimension.Height;
float hresolution = tif.HorizontalResolution;
float vresolution = tif.VerticalResolution;
tif.Dispose();



编辑:

这些TIFF文件二层和具有30x42英寸的尺寸。文件大小约为1〜2 MB。因此,上述方法效果好,但是进展缓慢。

Those tiff files are Bilevel and have a dimension of 30x42 inch. The file sizes are about 1~2 MB. So the method above works Ok but slow.

推荐答案

遇到了这个自己,找到了解决办法(可能是在这里)。 Image.FromStream validateImageData = FALSE 允许您访问您正在寻找的信息,而无需加载整个文件

Ran into this myself and found the solution (possibly here). Image.FromStream with validateImageData = false allows you access to the information you're looking for, without loading the whole file.

using(FileStream stream = new FileStream(@"C:\large_size.tif", FileMode.Open, FileAccess.Read))
{
  using(Image tif = Image.FromStream(stream, false, false))
  {
    float width = tif.PhysicalDimension.Width;
    float height = tif.PhysicalDimension.Height;
    float hresolution = tif.HorizontalResolution;
    float vresolution = tif.VerticalResolution;
  }
}

这篇关于阅读TIFF文件的尺寸和分辨率,而不先加载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆