Is there any way in C# or maybe a Third Party Library to get the file
properties?
If, in windows, I check the properties of an image I can see the size,
dimensions, type, etc.
And the same for other file types ...
Getting dimensions etc. of an image requires image format specific
code.
The code can located various places:
* some .NET code within the framework
* some third party .NET code
* some native code
* some C# code you write yourself
As an example of the lat option I am attaching some code
I wrote for TIFF many years ago.
Arne
====
using System;
using System.IO;
namespace E
{
public class TiffDim
{
public struct HWDim
{
public int H;
public int W;
}
private static short ReadWord(Stream stm, int ix)
{
stm.Seek(ix, SeekOrigin.Begin);
byte[] word = new byte[2];
stm.Read(word, 0, 2);
return BitConverter.ToInt16(word, 0);
}
private static int ReadDWord(Stream stm, int ix)
{
stm.Seek(ix, SeekOrigin.Begin);
byte[] dword = new byte[4];
stm.Read(dword, 0, 4);
return BitConverter.ToInt32(dword, 0);
}
public static HWDim Find(string fnm)
{
HWDim res = new HWDim();
using(Stream stm = new FileStream(fnm, FileMode.Open,
FileAccess.Read))
{
int ix = ReadWord(stm, 4);
for(;
![Wink ;) ;)](/styles/default/custom/smilies/wink.gif)
{
int ntag = ReadWord(stm, ix);
ix += 2;
for(int i = 0; i < ntag; i++)
{
int tagid = ReadWord(stm, ix);
if(tagid == 257)
{
res.H = ReadDWord(stm, ix + 8);
}
else if(tagid == 256)
{
res.W = ReadDWord(stm, ix + 8);
}
ix += 12;
}
ix = ReadDWord(stm, ix);
if(ix == 0) break;
}
}
return res;
}
public static void Main(string[] args)
{
HWDim hw = TiffDim.Find(@"C:\test.tif");
Console.WriteLine(hw.H + " " + hw.W);
}
}
}