public class Main
{
public static void main(String[] args)
{
BinaryReader myFile;
byte b1, b2;
int width, height;
myFile = new BinaryReader(File.Open("example.bmp", FileMode.Open));
b1 = myFile.ReadByte();
b2 = myFile.ReadByte();
if ((b1 == 0x42) && (b2 == 0x4D))
{
System.out.println("It seems to be a BMP file");
myFile.BaseStream.Seek(18, SeekOrigin.Begin);
width = myFile.ReadInt32();
height = myFile.ReadInt32();
System.out.printf("Width: %1$s pixels" + "\r\n", width);
System.out.printf("Height: %1$s pixels" + "\r\n", height);
}
else
{
System.out.println("It DOES NOT seem to be a BMP file");
}
myFile.Close();
}
}