import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.awt.Color;
public class bmpReader {
/**
* @param args
* @return
* @throws IOException
*/
public static void ReadBMPPic(String src) throws IOException
{
FileInputStream fis=new FileInputStream(src);
BufferedInputStream bis=new BufferedInputStream(fis);
//丢掉文件头信息
bis.skip(38);
//获取biXPelsPerMeter与biYPelsPerMeter
byte[] b1=new byte[4];
bis.read(b1);
byte[] b2=new byte[4];
bis.read(b2);
int Xdpi=byte2Int(b1);
int Ydpi=byte2Int(b2);
System.out.println("biXPelsPerMeter:"+Xdpi+" biYPelsPerMeter:"+Ydpi);
bis.close();
}
private static int byte2Int(byte[] b) throws IOException {
int num = (b[3]&0xff)<<24 | (b[2]&0xff)<<16 | (b[1]&0xff)<<8 | b[0]&0xff;
return num;
}
public static void main(String[] args) throws IOException {
ReadBMPPic("background_img11.bmp");
}
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.awt.Color;
public class bmpReader {
/**
* @param args
* @return
* @throws IOException
*/
public static void ReadBMPPic(String src) throws IOException
{
FileInputStream fis=new FileInputStream(src);
BufferedInputStream bis=new BufferedInputStream(fis);
//丢掉文件头信息
bis.skip(38);
//获取biXPelsPerMeter与biYPelsPerMeter
byte[] b1=new byte[4];
bis.read(b1);
byte[] b2=new byte[4];
bis.read(b2);
int Xdpi=byte2Int(b1);
int Ydpi=byte2Int(b2);
System.out.println("biXPelsPerMeter:"+Xdpi+" biYPelsPerMeter:"+Ydpi);
bis.close();
}
private static int byte2Int(byte[] b) throws IOException {
int num = (b[3]&0xff)<<24 | (b[2]&0xff)<<16 | (b[1]&0xff)<<8 | b[0]&0xff;
return num;
}
public static void main(String[] args) throws IOException {
ReadBMPPic("background_img11.bmp");
}