`

java 获取图片高和宽

阅读更多
public static Map<String,Integer> getImageWH(byte[] bytes ){

Map<String,Integer> map = new HashMap<String,Integer>();
if(bytes==null){
map.put("w", 0);
map.put("h", 0);
return map;
}

try{
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
BufferedImage bi = ImageIO.read(stream);
int srcWidth = bi.getWidth(); // 源图宽度
int srcHeight = bi.getHeight(); // 源图高度
map.put("w", srcWidth);
map.put("h", srcHeight);
}catch(Exception ex){
logger.error("getImageWH get image w and h has error!");
ex.printStackTrace();
map.put("w", 0);
map.put("h", 0);
return map;
}
return map;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics