如何读取自定义TIFF标记(不带TIFFFieldInfo)
How to read custom TIFF tags (w/o TIFFFieldInfo)
我正在尝试读取tiff文件中的自定义标记。
关于这个主题的指令很少,但AFAIK他们使用的是一个名为TIFFieldInfo的接口(结构)。我已经阅读了文档,TIFFFieldInfo再次出现。我可以同意,但他们(图书馆)说,接口已经过时了。你能给我推荐一些合理的替代方案吗?还是我看错了头文件?
终于找到了解决方案。手册(TIFFGetField(3tiff))说明了我们所需要的一切。请参阅AUTOREGISTED TAGS会话。下面是复制粘贴的。
AUTOREGISTED TAGS如果你在上表中找不到标签意味着这是一个不受支持的标记,并且不是直接的由libtiff(3TIFF)库支持。你仍然可以阅读如果您知道该标记的数据类型,则它是有价值的。例如,如果想要从标记33424中读取LONG值,并从中读取ASCII字符串标签36867您可以使用以下代码:
uint32 count; void *data; TIFFGetField(tiff, 33424, &count, &data); printf("Tag %d: %d, count %d0", 33424, *(uint32 *)data, count); TIFFGetField(tiff, 36867, &count, &data); printf("Tag %d: %s, count %d0", 36867, (char *)data, count);
例如,我需要读取一个双标签,所以我使用了以下代码(但我没有检查IT):
tiff *tif = TIFFOpen("ex_file.tif", "rc"); // read tif
static ttag_t const TIFFTAG_SOMETAG = 34362; // some custom tag
if(tif != nullptr) // if the file is open
{
uint count; // get count
double *data; // get data
if(TIFFGetField(tif, TIFFTAG_SOMETAG, &count, &data) == 1) // read tag
throw std::logic_error("the tag does not exist.");
// print the values (caution: count is in bytes)
for(int index = 0; index < count / sizeof(double); ++index)
std::cout << data[index];
TIFFClose(tif); // close the file
}
else
throw std::runtime_error("cannot open the file");
相关文章:
- 使用不带参数的函数访问结构元素
- 不带大括号的枚举形式
- 将静态库链接到不带-fPIC的共享库中
- 检查不带转换的扫描格式
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 不带预处理器的调用方法/文件的文件名/行号
- 如何打印不带空格的输入整数?
- 带<T>或不带 (C++) 的类模板
- 声明C++数组(带或不带 "new" 关键字)
- 不带轮询的 SDL2 事件回调
- 多个'if'语句,不带'else'
- 使用不带缓冲区变量的冲刺
- "extern"声明以及带有和不带参数列表的类模板实例的后续定义
- 打印标准::<char>不带无关字符的矢量
- f 是指向函数的指针,该函数采用 int,并返回指向不带任何内容并返回双精度的函数的指针
- 调用多个类而不带 if 语句
- 在 c++ 中,rand() 在执行有调试和不带调试的程序时生成不同的结果
- 使用不带Unicode字节顺序标记的iconv进行字符转换
- 如何读取自定义TIFF标记(不带TIFFFieldInfo)
- 具有多个分隔符的字符串标记器,包括不带Boost的分隔符