使用libtiff读取TIFF灰度

时间:2013-07-12 14:51:38

标签: c tiff libtiff

所以我有这个程序,还没有完成。我的图像是8或16位。如何将来自buf的任何值分配给缓冲区数组?现在,在buf之后的printf不起作用,因为它说buf属于void * ...我不知道如何处理它。

void read_tiff(image_file_name,buffer)
      char   image_file_name[];
      short **buffer;
{
    int i,j;
    tsize_t scanline;
    tdata_t buf;
uint32 width;
uint32 height;
TIFF *tif = TIFFOpen(image_file_name,"r");

if(tif){
TIFFGetField(tif,TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(tif,TIFFTAG_IMAGELENGTH, &height);

buf = _TIFFmalloc(TIFFScanlineSize(tif));


printf("width height %d %d\n",width,height);
for(i=0;i<height;i++){
    TIFFReadScanline(tif,buf,i);
    printf("%d ",buf[j]);
}   

_TIFFfree(buf);
TIFFClose(tif);
}
else{
    printf("ERROR- cannot open image %s\n",image_file_name);
}
} 

1 个答案:

答案 0 :(得分:1)

您无法取消引用void *,您需要先将其投射。

例如,如果将其强制转换为字节:

printf("%d ", ((unsigned char *) buf)[j]);