If you want to get that information without actually constructing an Image
object instance for each image, you'll need to write code that reads each individual image file and extracts the information. Although certainly possible, you'll find it somewhat involved. First, you'll need code that reads the first few bytes of the file to determine what type of image (.bmp, .gif, .png, .jpg, etc.) is contained in the file, and then you'll need special code to extract the information for each image type that you support.
Whereas the above would almost certainly be faster than code that loads the entire image, extracts the relevant data, and then destroys the image, I can't say how much faster. It's quite possible that the execution time savings doesn't justify the amount of time you'll put into such a solution.
Were I writing this program, my first cut would do as ChrisF suggested, and write something like:
foreach (string filename in ImageFilenames)
{
using (Bitmap bmp = new Bitmap(filename))
{
// extract and store needed information
}
}
Once you get that working, you can decide if it's fast enough for your purposes. If it's not, then I would suggest a test where you modify that loop to simulate extracting the information by reading the first kilobyte or so from each file:
foreach (string filename in ImageFilenames)
{
using (File f = File.OpenRead(filename))
{
// read the first 1K from the file
// store some placeholder data for height/width
}
}
If that performs significantly faster than the first, then it's probably worth investigating the possibility of doing your own image header parsing. Be aware, though, that you're opening a big can of worms. Image header parsing can get quite involved.