从libtiff 下载地址下载一个版本,这里选择4.0.8.

E:\cpp_lib\tiff-4.0.8

这里要选择x86_x64 Cross Tools Command Prompt for VS 2019。

点击输入以下命令:
cd /d E:\cpp_lib\tiff-4.0.8
nmake /f makefile.vc


新建一个cpp项目。



#include
using namespace std;
#include "tiffio.h"
int main()
{
int m_ImWidth, m_ImHeight;
uint16_t bits_per_sample, samples_per_pixel;
TIFF* tif = TIFFOpen("E:/1.tif", "r");
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &m_ImWidth);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &m_ImHeight);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample);
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel);
cout << m_ImWidth << " " << m_ImHeight << endl;
cout << bits_per_sample << " " << samples_per_pixel << endl;
size_t scanline_size = TIFFScanlineSize(tif);
cout << " scanline_size:" << scanline_size << endl;
uint16_t* m_ImFFT0 = (uint16_t*)_TIFFmalloc(m_ImWidth * m_ImHeight* bits_per_sample);
for (uint32_t row = 0; row < m_ImHeight; row++)
{
TIFFReadScanline(tif, m_ImFFT0 + row * m_ImWidth, row);
}
TIFFClose(tif);
return 0;
}
结果为:
3136 2704
使用libtiff库出现无法解析的外部符号的错误,可参考vs c++ debug 之路。