using System;
using System.IO;
public class exercise188
{
public static void Main()
{
FileStream myFile;
byte[] data;
int width, height;
const int SIZE = 54;
Console.Write("Enter the name of file: ");
string fileName = Console.ReadLine();
if (!File.Exists(fileName))
{
Console.WriteLine("The file not exists!!!");
return;
}
try
{
myFile = File.OpenRead(fileName);
data = new byte[SIZE];
myFile.Read(data, 0, SIZE);
myFile.Close();
byte b1 = data[0];
byte b2 = data[1];
if ((Convert.ToChar(b1) != 'B')
|| (Convert.ToChar(b2) != 'M'))
{
Console.WriteLine("This File is NOT a BMP file");
return;
}
width = data[18] + (data[19] * 256) + (data[20] * 256 * 256) +
(data[21] * 256 * 256 * 256);
height = data[22] + (data[23] * 256) + (data[24] * 256 * 256) +
(data[25] * 256 * 256 * 256);
Console.WriteLine("Width: {0} - Heigth: {1}", width, height);
}
catch (Exception e)
{
Console.WriteLine("Error: {0}!!!", e.message());
}
}
}