使用libtiff存储TIFF格式图片,图片只存储了2045张?

Barthes 2014-07-31 11:56:08
在windows7,32位的系统上建立的windows console application,想要使用libtiff库来输出一系列的TIFF格式的文件,因为需要输出的文件数目有30000张之多,因此使用了for循环。但是,发现在编译成功后,运行时,输出的文件数目总是在2045时,程序就发生错误。不能达到要求的文件数目。下面是我的代码(这个代码只是为了验证文件生成数目的会不会被限制)我的libtiff库所需要的必要库文件和头文件都是自己编译的。
PS:这个问题在Google上搜索了一下,貌似也有人需要相似的问题,但是都没有给出明确的解决方法,我自己猜想不知道是不是系统的问题,因为libtiff是在Linux系统下编写的库,还有就是我发现在TIFFClose(image)之后,image的值并没有变化,所以我怀疑是不是tiffclose并没有起作用,但是将tiffclose注释掉后,发现文件的数目只能输出1024个,所以自己真的是不明所以了,恳请各位图像处理的大神,能够给与一丝帮助。
#include <stdio.h>
#include <iostream>
#include "tiffio.h"

#pragma comment( lib, "libtiff.lib" )
using namespace std;

#define XSIZE 100
#define YSIZE 120

int main(int argc, char *argv[])
{

TIFF *image;
uint32 image_width, image_height;
uint16 spp, bpp;
int i, j;
char szFileName[100];

uint16 array[XSIZE * YSIZE];
for (j = 0; j < YSIZE; j++)
{
for(i = 0; i < XSIZE; i++)
{
array[j * XSIZE + i] = i * j;
}
}
for( int m=1; m<=5000; m++)
{
sprintf(szFileName,"F:\\chenjun\\data\\%d.tif",m);
image = TIFFOpen(szFileName, "w");
// Open the TIFF file
if((image = TIFFOpenW(szFileName, "w")) == NULL)
{
cout<<"can not open the "<<szFileName<<" to write."<<endl;
return 1;
}
image_width = XSIZE;
image_height = YSIZE;
spp = 1; /* Samples per pixel */
bpp = 16; /* Bits per sample */
// We need to set some values for basic tags before we can add any data
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, image_width);//set the width
TIFFSetField(image, TIFFTAG_IMAGELENGTH, image_height);//set the height
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, bpp);//set the size of the channels
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, spp);//set number of channels per pixel
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, image_width);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_XRESOLUTION, 96.0);
TIFFSetField(image, TIFFTAG_YRESOLUTION, 96.0);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
for (int n = 0; n< image_height; n++)
{
TIFFWriteScanline(image, &array[n * image_width], n, 0);
}
TIFFClose(image);// Close the file

}
return 0;
}
...全文
206 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Barthes 2014-07-31
  • 打赏
  • 举报
回复
感谢一楼的答复,经过改正后真的可以了。
  • 打赏
  • 举报
回复
这个没有用过,不过看问题,似乎是,用完后句柄没有关闭,继续用同样的句柄打开下一个。造成的。 image = TIFFOpen(szFileName, "w"); // Open the TIFF file 把上面的那一句去掉应当就可以了。试试吧。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧