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;
        }
    }

}
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐