java解析webp格式图片宽高;java解析webp图片转png格式
package 你的包名:***.***.***.***;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* 图片处理工具类
*/
public class ImageUtils {
/**
* 解析webp格式图片宽高
*
* @param inputStream IO输入流
*/
public static ImageBean webpToPng(InputStream inputStream) throws IOException {
byte[] bytes = new byte[30];
inputStream.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);
ImageBean imageBean = new ImageBean();
imageBean.setWidth(width);
imageBean.setHeight(height);
return imageBean;
}
/**
* 图片对象
*/
public static class ImageBean {
private Integer width; //宽度
private Integer height; //高度
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
}