我正在尝试保存一个tiff文件格式的图像。我用libraw从相机读取原始数据,它给了我没有签名的短数据。我已经对数据做了一些操作,我想用Tiff文件格式将结果保存为16位灰度(1通道)图像。但结果只是一个空白的图像。即使我使用保持原始拜耳图像的缓冲区,它也不会正确保存。这是我用来保存的代码:
// Open the TIFF file
if((output_image = TIFFOpen("image.tiff", "w")) == NULL){
std::cerr << "Unable to write tif file: " << "image.tiff" << std::endl;
}
TIFFSetField(output_image, TIFFTAG_IMAGEWIDTH, width());
TIFFSetField(output_image, TIFFTAG_IMAGELENGTH, height());
TIFFSetField(output_image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(output_image, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField(output_image, TIFFTAG_ROWSPERSTRIP, 1);
TIFFSetField(output_image, TIFFTAG_ORIENTATION, (int)ORIENTATION_TOPLEFT);
TIFFSetField(output_image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(output_image, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(output_image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
// Write the information to the file
tsize_t image_s;
if( (image_s = TIFFWriteEncodedStrip(output_image, 0, &m_data_cropped[0], width()*height())) == -1)
{
std::cerr << "Unable to write tif file: " << "image.tif" << std::endl;
}
else
{
std::cout << "Image is saved! size is : " << image_s << std::endl;
}
TIFFWriteDirectory(output_image);
TIFFClose(output_image);
发布于 2014-01-11 07:35:34
看起来您的代码中有两个问题。
TIFFWriteEncodedStrip
编写整个映像,但同时将TIFFTAG_ROWSPERSTRIP
设置为1
(在这种情况下,您应该将其设置为height()
)。TIFFWriteEncodedStrip
。最后一个参数是带的长度(以字节为单位),您显然是在传递长度(以像素为单位)。我不确定&m_data_cropped[0]
参数是否指向整个图像的第一个字节,因此您可能也希望检查该参数的正确性。
https://stackoverflow.com/questions/21049153
复制相似问题