//TIFFSetDirectory(tiff,0);//我们打开第一幅图,也就是第0帧,如果是第1帧,第二个参数写1,由此类推。因为Windows下图像基本//操作都是以BMP格式进行,我们读出该帧并转成BMP格式。
char* szFileName = "C:\Users\Administrator\Desktop\test.tiff";
TIFF* tiff = TIFFOpen(szFileName, "r"); //打开Tiff文件,得到指针,以后所有的操作都通过指针进行
int nTotalFrame = TIFFNumberOfDirectories(tiff); //得到图像的总帧数
char *dtitle;
// TIFFGetField(tiff,TIFFTAG_PAGENAME,&dtitle);
//得到该帧的名字,存放在dtitle中。
int width,height;
TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &width); //得到宽度
TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height);//得到高度
float resolution = max(width,height);
uint16 bitspersample = 1;
uint16 samplesperpixel = 1;
TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
//每个像素占多少机器字,24位图samplesperpixel应该等于3。
TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bitspersample);
//每一个机器字长,这里应为8。
uint16 bitsperpixel = bitspersample * samplesperpixel;
//算出每个像素占多少bit,24位图,值为24
DWORD dwBytePerLine = (width*bitsperpixel+31)/32 *4;
//由上面几个参数算出图像每行所占字节(BYTE)数。
DWORD64 dwLeng = height*dwBytePerLine;//在内存里存放这帧图像数据所需要的长度
BYTE* pData = new BYTE[dwLeng]; //为存放数据分配内存空间
uint32* raster;
uint32 *row;
raster = (uint32*)_TIFFmalloc(width * height * sizeof (uint32));
TIFFReadRGBAImage(tiff, width, height, (uint32*)raster, 0);
//以上几行读出该帧数据,保存到raster中。
row = &raster[0];
LPBYTE bits2 = pData;
for (int y = 0; y < height; y++)
{
LPBYTE bits = bits2;
for (int x = 0; x < width; x++)
{
*bits++ = (BYTE)TIFFGetB(row[x]);
*bits++ = (BYTE)TIFFGetG(row[x]);
*bits++ = (BYTE)TIFFGetR(row[x]);
}
row += width;
bits2 += dwBytePerLine;
}
_TIFFfree(raster);
这样出来的图像数据不对,只有一部分,啥原因啊