微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C LibTiff – 从和内存中读取并保存文件

在LibTiff中有没有办法如何从内存中读取文件并将其保存到内存?

我不想先将图像保存到光盘,然后再用其他的图库打开它.

非常感谢!

解决方法

我知道这是一个古老的问题,但是我将为需要这些信息的人们提供一个更简单,更新的最新的答案,这些信息需要更多最新版本的libtiff.在最新版本的libtiff(4.0.2)中,甚至过去几个版本我相信(检查您的具体版本号),还有一个名为tiffio.hxx的包含文件.它有两个外部函数用于读/写内存中的流:
extern TIFF* TIFFStreamOpen(const char*,std::ostream *);
extern TIFF* TIFFStreamOpen(const char*,std::istream *);

您可以只包含这个文件并读取或写入内存.

写作范例:

#include <tiffio.h>
#include <tiffio.hxx>
#include <sstream>    

std::ostringstream output_TIFF_stream;

//Note: because this is an in memory TIFF,just use whatever you want for the name - we 
//aren't using it to read from a file
TIFF* mem_TIFF = TIFFStreamOpen("MemTIFF",&output_TIFF_stream);

//perform normal operations on mem_TIFF here like setting fields
//...

//Write image data to the TIFF 
//..

TIFFClose(created_TIFF);   

//Now output_TIFF_stream has all of my image data. I can do whatever I need to with it.

阅读非常相似:

#include <tiffio.h>
#include <tiffio.hxx>
#include <sstream>

std::istringstream input_TIFF_stream;
//Populate input_TIFF_stream with TIFF image data
//...

TIFF* mem_TIFF = TIFFStreamOpen("MemTIFF",&input_TIFF_stream);

//perform normal operations on mem_TIFF here reading fields
//...

TIFFClose(created_TIFF);

这些是非常简单的例子,但您可以看到,通过使用TIFFStreamOpen,您不必重写这些函数并将它们传递给TIFFClientOpen.

原文地址:https://www.jb51.cc/c/114751.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐