//Opentheoutputimage
if((output=TIFFOpen("123456.tif","w"))==NULL)
{
//fprintf(stderr,"Couldnotopenoutgoingimage\n");
returnfalse;
}
//Writethetifftagstothefile
TIFFSetField(output,TIFFTAG_IMAGEWIDTH,width);
TIFFSetField(output,TIFFTAG_IMAGELENGTH,height);
TIFFSetField(output,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
//给定的像素的CMYK信息一起分在图像数据的条纹中,另一个选项是PLANARCONFIG_SEPARATE,图像的C样本存在一起,M样本存在一起,最后Y样本存在一起。
//TIFFSetField(output,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_RGB);//PHOTOMETRIC_RGB标记声明图像数据存储在条纹本身(而不是通过调色板)
TIFFSetField(output,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_SEPARATED);
//TIFFSetField(output,TIFFTAG_BITSPERSAMPLE,8,8,8,8);//每个样本占用的bit
TIFFSetField(output,TIFFTAG_BITSPERSAMPLE,8);//每个样本占用的bit
//TIFFSetField(output,TIFFTAG_SAMPLESPERPIXEL,4);//每个像素有几个样本sample
TIFFSetField(output,TIFFTAG_SAMPLESPERPIXEL,channelNum);//每个像素有几个样本sample
//TIFFSetField(output,TIFFTAG_INKNAMES,"red");
uint8info[8]={0};//2016-12-13保存大于6位通道TIF图像错误,设置数组[8],支持到8+4=12通道
uint8AlphaChannelNumer=channelNum-4;
//TIFFSetField(output,TIFFTAG_EXTRASAMPLES,AlphaChannelNumer,info);
TIFFSetField(output,TIFFTAG_INKSET,INKSET_CMYK);//这里设置了,但是没效果
TIFFSetField(output,TIFFTAG_NUMBEROFINKS,1);
TIFFSetField(output,TIFFTAG_INKNAMES,"red");
TIFFSetField(output,TIFFTAG_IMAGEBASECOLOR,255);
//Actuallywritetheimage
//if(TIFFWriteEncodedStrip(output,0,raster,width*height*4)==0){
if(TIFFWriteRawStrip(output,0,memory,width*height*channelNum)==0){
//fprintf(stderr,"Couldnotwriteimage\n");
return1;
}
TIFFClose(output);
分 --> |