解决方法
我知道这是一个古老的问题,但是我将为需要这些信息的人们提供一个更简单,更新的最新的答案,这些信息需要更多最新版本的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.