Get Horizontal Resolution from .tif in C?

Use libTIFF Read the fields (sample code here ) Profit!

Use libTIFF Read the fields (sample code here) Profit!

If you just want to get one or two fields from the header then adding libtiff may be overkill. In this case you can parse the file yourself and locate the tags that you want, the format is quite simple to parse. See the file format details and tag reference.

Below is an example which reads the horizontal and vertical resolution from a TIFF file. As reference I used the TIFF Revision 6.0 sections 2 and 8 (TIFF structure, IFD structure and data types). Please note: the example only treats the LSB byte order case and only the first image in the TIFF file.

A good implementation must also take into account the MSB order and multiple images per file (which could have different resolutions). I appologize for bugs that may have slipped in (unintentionally). Source was compiled with Borland C++ 3.1.I tried to keep it as simple as I could... #include #include //converts a 4-byte LSB order array to ULong unsigned long lsbToUL(unsigned char *buff) { unsigned long val=0; int i=0; for(i=3;i>0;i--) val=(val+buffi)Seekg(4); //seeks the offset of first IFD from header f.

Get(buff,5); //reads the address of the first IFD seekAddr=lsbToUL(buff); seekAddr=seekAddr+2; f. Seekg(seekAddr); //seeks the addr of the first TIFF tag //skipping the no. Of directory entries as it is not used f.

Get(buff,3); //reads the first TIFF tag tag=lsbToUI(buff); //reading the file for XRES,YRES and UNIT TIFF tags //should be a better way of doing this while(xAddr==0 || yAddr==0 || resUnit==0) { if(tag==UNIT || tag==XRES || tag==YRES) { if(tag==UNIT) { f. Seekg(seekAddr+8); f. Get(buff,3); //read the Resolution Unit resUnit=lsbToUI(buff); *unit=resUnit; } else { f.

Seekg(seekAddr+8); f. Get(buff,5); //reads the address of the XRes or YRes if(tag==XRES) xAddr=lsbToUL(buff); //XRes address else yAddr=lsbToUL(buff); //YRes address } } seekAddr=seekAddr+12; //computes the address of next IFD f. Seekg(seekAddr); //seeks the next IFD f.

Get(buff,3); //reads the next tag tag=lsbToUI(buff); } //actual reading of the resolution values //X resolution f. Seekg(xAddr); f. Get(buff,5); *xRes=lsbToUL(buff); f.

Seekg(xAddr+4); f. Get(buff,5); *xRes=*xRes/(double)lsbToUL(buff); //Y resolution f. Seekg(yAddr); f.

Get(buff,5); *yRes=lsbToUL(buff); f. Seekg(yAddr+4); f. Get(buff,5); *yRes=*yRes/(double)lsbToUL(buff); f.close(); } else { //Not covered by the example f.close(); if(buff0==0x4D && buff1==0x4D) cout.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions