📄 bmpinfoheader.java
字号:
import java.util.HashMap;
import java.io.IOException;
public class BMPInfoHeader {
//图象信息头
public final static int PIXEL_BITS = 0X1C;
public final static int COMPRESSION = 0X1E;
public final static int BMP_DATA_SIZE = 0X22;
public final static int H_RESOLUTION = 0X26;
public final static int V_RESOLUTION = 0X2A;
public final static int COLORS = 0X2E;
public final static int IMPORTANT_COLORS= 0X32;
public final static HashMap<Integer,Integer> lengthMap = new HashMap<Integer,Integer>(7);
//set length map
{
lengthMap.put(PIXEL_BITS,2);
lengthMap.put(COMPRESSION,4);
lengthMap.put(BMP_DATA_SIZE,4);
lengthMap.put(H_RESOLUTION,4);
lengthMap.put(V_RESOLUTION,4);
lengthMap.put(COLORS,4);
lengthMap.put(IMPORTANT_COLORS,4);
}
private int pixelBits;
private int compression;
private int BMPDataSize;
private int HResolution;
private int VResolution;
private int colorNum;
private int importantColors;
public void fill(BMPReader reader) throws IOException {
pixelBits = reader.readData(PIXEL_BITS, lengthMap.get(PIXEL_BITS));
compression = reader.readData(COMPRESSION, lengthMap.get(COMPRESSION));
BMPDataSize = reader.readData(BMP_DATA_SIZE, lengthMap.get(BMP_DATA_SIZE));
HResolution = reader.readData(H_RESOLUTION, lengthMap.get(H_RESOLUTION));
VResolution = reader.readData(V_RESOLUTION, lengthMap.get(V_RESOLUTION));
colorNum = reader.readData(COLORS , lengthMap.get(COLORS));
importantColors = reader.readData(IMPORTANT_COLORS, lengthMap.get(IMPORTANT_COLORS));
}
public String toString() {
return "(pixelBits=" + pixelBits + "," +
"compression=" + compression + "," +
"BMPDataSize=" + BMPDataSize + "," +
"HResolution=" + HResolution + "," +
"VResolution=" + VResolution + "," +
"colorNum=" + colorNum + "," +
"importantColors=" + importantColors + ")" ;
}
public String toString16() {
return "(pixelBits=" + Integer.toHexString(pixelBits) + "," +
"compression=" + Integer.toHexString(compression) + "," +
"BMPDataSize=" + Integer.toHexString(BMPDataSize) + "," +
"HResolution=" + Integer.toHexString(HResolution) + "," +
"VResolution=" + Integer.toHexString(VResolution) + "," +
"colorNum=" + Integer.toHexString(colorNum) + "," +
"importantColors=" + Integer.toHexString(importantColors) + ")" ;
}
public int getPixelBits() {
return pixelBits;
}
public void setPixelBits(int aPixelBits) {
pixelBits = aPixelBits;
}
public int getCompression() {
return compression;
}
public void setCompression(int aCompression) {
compression = aCompression;
}
public int getBMPDataSize() {
return BMPDataSize;
}
public void setBMPDataSize(int aBMPDataSize) {
BMPDataSize = aBMPDataSize;
}
public int getHResolution() {
return HResolution;
}
public void setHResolution(int aHResolution) {
HResolution = aHResolution;
}
public int getVResolution() {
return VResolution;
}
public void setVResolution(int aVResolution) {
VResolution = aVResolution;
}
public int getColorNum() {
return colorNum;
}
public void setColorNum(int aColorNum) {
colorNum = aColorNum;
}
public int getImportantColors() {
return importantColors;
}
public void setImportantColors(int anImportantColors) {
importantColors = anImportantColors;
}
public static void main(String[] args) throws Exception {
String fileName = "girl.bmp";
String mode = "rw";
BMPReader reader = new BMPReader(fileName,mode);
BMPInfoHeader aBMPInfoHeader = new BMPInfoHeader();
aBMPInfoHeader.fill(reader);
System.out.println(aBMPInfoHeader);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -