我需要处理位图图像的正文部分,为此我需要跳过位图图像的标题部分。
如何识别位图图像标题占用的字节数?这就是我现在所做的,但必须有更好的方法:
class Test{
public static void main(String ... a){
try{
//I can't find any ideas to skip the header portion of bmp image
FileInputStream fis=new FileInputStream("C:\\ja\\text1.bmp");
BufferedImage bi=ImageIO.read(fis);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
ImageIO.write(bi,"bmp",baos);
baos.flush();
byte [] data=baos.toByteArray();
baos.close();
double i=0;
System.out.print(data.length);
while(i<data.length){
//data[(int)i]=(byte)0xFF;
if(i>5000d && i<17000d)
data[(int)i]=0;
i++;
}
//edit it.....
ByteArrayInputStream bais=new ByteArrayInputStream(data);
bi=ImageIO.read(bais);
ImageIO.write(bi,"bmp",new File("C:\\ja\\text2.bmp"));
}
catch(Exception e){
e.printStackTrace();
}
}
}