我想使用 tiles 创建一个大型TIFF RGBA图像。我编写了以下程序,它循环遍历瓷砖的位置,但生成的图像始终是透明的。为什么?
#include <math.h>
#include <stdlib.h>
#include "tiffio.h"
int main(int argc,char** argv)
{
uint32 width=400, height=400;
uint32 tileWidth=16, tileHeight=16;
TIFF* tif = TIFFOpen("foo.tif", "w");
int i,j,x;
int spp=4;
int bps = 8;
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL,spp);//R G B A
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
TIFFSetField(tif, TIFFTAG_TILEWIDTH, tileWidth);
TIFFSetField(tif, TIFFTAG_TILELENGTH, tileHeight);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
int tilesize = tileWidth * tileHeight * bps/8 * spp;
uint8 *buf = malloc(tilesize);
for ( j = 0; j < width; j += tileWidth) {
for ( i = 0; i < height; i += tileHeight)
{
for ( x = 0; x < tilesize; x+=spp)
{
uint8 a = 100;
buf[x+0] =a;
buf[x+1] =a;
buf[x+2] =a;
buf[x+3] =a;
}
if(TIFFWriteTile(tif, buf, i, j, 0, 0)<0) exit(-1);
}
}
free(buf);
TIFFClose(tif);
return 0;
}