=====================码上见==========================
void CreatTiffFileGRAY(const char *FileName, unsigned char *Buf, uint32 width, uint32 height)
{
int image_height = height;
int image_width = width;
DWORD* data = (DWORD*)Buf;
TIFF *imageTest = TIFFOpen(FileName, "w");
if (imageTest == NULL) {
printf("Could not open output.tif for writing\n");
cout << "open is failed.\n";
system("pause");
exit(1);
}
int NPAGE = 6;//可以是1
for (size_t i = 0; i < NPAGE; i++)
{
TIFFSetField(imageTest, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
/* Set the page number */
TIFFSetField(imageTest, TIFFTAG_PAGENUMBER, i, NPAGE);
//上面两句不写测着也可以
TIFFSetField(imageTest, TIFFTAG_IMAGEWIDTH, image_width);
TIFFSetField(imageTest, TIFFTAG_IMAGELENGTH, image_height);
TIFFSetField(imageTest, TIFFTAG_BITSPERSAMPLE, 16);// 可以改到8,数据类型要改
TIFFSetField(imageTest, TIFFTAG_SAMPLESPERPIXEL, 1);//可以改到3,存储彩色图像
TIFFSetField(imageTest, TIFFTAG_ROWSPERSTRIP, image_height);
TIFFSetField(imageTest, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(imageTest, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);//PHOTOMETRIC_RGB
TIFFSetField(imageTest, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
/* It is good to set resolutions too (but it is not nesessary) */
auto xres = 100; auto yres = 100;
TIFFSetField(imageTest, TIFFTAG_XRESOLUTION, xres);
TIFFSetField(imageTest, TIFFTAG_YRESOLUTION, yres);
TIFFSetField(imageTest, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
for (int j = 0; j < image_height; j++)
TIFFWriteScanline(imageTest, data + j * image_width, j, i);
TIFFWriteDirectory(imageTest);
}
TIFFClose(imageTest);
}