// Open the output image
if ((output = TIFFOpen("123456.tif", "w")) == NULL)
{
//fprintf(stderr, "Could not open outgoing image\n");
return false;
}
// Write the tiff tags to the file
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");
uint8 info[8] = { 0 }; // 2016-12-13 保存大于6位通道TIF影像錯誤,設定陣列[8],支持到8+4=12通道
uint8 AlphaChannelNumer = 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);
// Actually write the image
//if (TIFFWriteEncodedStrip(output, 0, raster, width * height * 4) == 0){
if (TIFFWriteRawStrip(output, 0, memory, width * height * channelNum) == 0){
//fprintf(stderr, "Could not write image\n");
return 1;
}
TIFFClose(output);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/28707.html
標籤:圖形處理/算法
上一篇:VC
