i am in trouble. how to read 1MB .tif file with bitmap class in c#. i used below code but getting error “Out of memory”.I searched google lot but not find any answer yet.
string imgPath;
imgPath = @"C:\Documents and Settings\shree\Desktop\2012.06.09.15.35.42.2320.tif";
Image newImage = Image.FromFile(imgPath);
Bitmap img;
img = new Bitmap(imgPath, true);
MessageBox.Show("Width: "+ img.Width + " Height: " + img.Height);
If you just need to read the width and height of the file without loading it in memory you could use WPF’s BitmapDecoder class:
If for some reason you are stuck in some pre-.NET 3.0 era you could look at the image metadata to extract this information without loading the entire image in memory as shown in the following answer.