【问题标题】:Reading TIFF grayscale using libtiff使用 libtiff 读取 TIFF 灰度
【发布时间】:2013-07-12 14:51:37
【问题描述】:

所以我有这个程序,它还没有完成。我的图像将是 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);
}
} 

【问题讨论】:

    标签: c tiff libtiff


    【解决方案1】:

    您不能取消引用 void *,您需要先转换它。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多