{
// BMP format explained here:
// http://www.javaworld.com/article/2077561/learn-java/java-tip-60--saving-bitmap-files-in-java.html
// we skip 38 bytes and then read two 4 byte-integers and reverse the bytes
DataInputStream dis = new DataInputStream(new FileInputStream(new File(filename)));
int skipped = dis.skipBytes(38);
assertEquals("Can't skip 38 bytes in image file " + filename, 38, skipped);
int pixelsPerMeter = Integer.reverseBytes(dis.readInt());
int actualResolution = (int) Math.round(pixelsPerMeter / 100.0 * 2.54);
assertEquals("X resolution doesn't match in image file " + filename,
expectedResolution, actualResolution);