public class DownTest {
public static void main(String[] args)throws Exception {
FileInputStream file = new FileInputStream("E:\\20171102_cf36c03d56fbdf6214c3e5d196b90e21.webp");
byte[] bytes = new byte[30];
file.read(bytes,0,bytes.length);
int width = ((int) bytes[27] & 0xff)<<8 | ((int) bytes[26] & 0xff);
int height = ((int) bytes[29] & 0xff)<<8 | ((int) bytes[28] & 0xff);
System.out.println(width);
System.out.println(height);
}
}
获取文件头的27 28 位计算得到宽 29 30得到高
本文介绍了一个简单的Java程序,用于从指定路径的webp格式图片中读取宽度和高度信息。通过读取文件特定位置的字节来计算图像的宽度和高度。
1632





