Can';无法正确写入tiff文件
我有一个程序,它具有以下功能来写入tiff文件。但是,任何图片查看软件都无法识别生成的文件。这段代码有什么问题,为什么不能生成正确的tiff文件?请注意,它使用Can';无法正确写入tiff文件,c,gcc,graphics,x86-64,tiff,C,Gcc,Graphics,X86 64,Tiff,我有一个程序,它具有以下功能来写入tiff文件。但是,任何图片查看软件都无法识别生成的文件。这段代码有什么问题,为什么不能生成正确的tiff文件?请注意,它使用libtiff库 long WriteGrayscaleTIFF(char *filename, long width, long height, long scanbytes, unsigned char *data) { long y; double factor; long c; u
libtiff
库
long WriteGrayscaleTIFF(char *filename, long width,
long height, long scanbytes, unsigned char *data)
{
long y;
double factor;
long c;
unsigned long cmap[256]; /* output color map */
TIFF *outimage; /* TIFF image handle */
/* create a grayscale ramp for the output color map */
factor = (double)((1 << 16) - 1) / (double)((1 << 8) - 1);
for (c = 0; c < 256; c++)
cmap[c] = (long)(c * factor);
/* open and initialize output file */
if ((outimage = TIFFOpen(filename, "w")) == NULL)
return(0);
TIFFSetField(outimage, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(outimage, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(outimage, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(outimage, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(outimage, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(outimage, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
TIFFSetField(outimage, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
TIFFSetField(outimage, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE);
TIFFSetField(outimage, TIFFTAG_COLORMAP, cmap, cmap, cmap);
/* write the image data */
printf( "height = %d, width = %d!\n", height, width );
for (y = 0; y < height; y++) {
if (!TIFFWriteScanline(outimage, data, y, 0))
{
printf( "TIFFClose!\n" );
TIFFClose(outimage);
return(0);
}
data += scanbytes;
}
/* close the file */
TIFFClose(outimage);
return(1);
}
long WriteGrayscaleTIFF(char*文件名,长宽度,
长高度、长扫描字节、无符号字符*数据)
{
长y;
双重因素;
长c;
无符号长cmap[256];/*输出颜色映射*/
TIFF*输出图像;/*TIFF图像句柄*/
/*为输出颜色贴图创建灰度渐变*/
factor=(double)((1)我刚刚测试了这个,它是有效的,你仍然有这个问题吗?