Sameer Gupta wrote:
what are options for opening / handling tiff files in .Net framework ?
which is the best library, namespace ?
Well, what is "best" depends very much on what you want to do, and how
much control you want.
If you just want to display images, the Image / Bitmap classes are
probably the ones you want. Be forewarned, though, that
Image.FromFile() leaves the TIF file locked for a while... probably
until the garbage collector gets around to doing something with the
objects that FromFile was using to read the file.
I read the TIF file into a MemoryStream and then feed it to
Image.FromStream(), like this:
Image fullImage;
System.IO.Stream st = System.IO.File.Open(imageFilePath,
System.IO.FileMode.Open, System.IO.FileAccess.Read,
System.IO.FileShare.Read);
try
{
byte[] b = new byte[st.Length];
st.Read(b, 0, b.Length);
System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
fullImage = Image.FromStream(ms);
}
finally
{
st.Close();
}
which ensures that the file lock is released as soon as possible.
Be also forewarned that the Image class limits your control over the
image format. There are a limited set of bit depths at your disposal,
for example, which can cause a lot of bloat in memory as tiny
black-and-white TIF images are blown out into (unnecessary) 8-bit or
16-bit colour in memory.
Nonetheless, if all you want to do is show pictures to your user, this
is no doubt the simplest way to do that.