根据图片完整路径,获得图片的宽和高,判断是横版还是竖版图片

来源:互联网 发布:兄弟连2016php百度云 编辑:程序博客网 时间:2024/04/27 14:53

判断图片是横版还是竖版图片,就要获得图片的宽和高,有两种获得方式

1、图片在同一个机器(本地)可以预览

/** * @function:根据图片完整路径,判断是横版还是竖版图片 * @param imagePath * @return true是竖版,false是横版 */private static boolean getVerticalImage(String imagePath) {boolean is_vertical = false;BufferedImage bufferedImage;try {bufferedImage = ImageIO.read(new File(imagePath));int height = bufferedImage.getHeight();int width = bufferedImage.getWidth();if (height > width) {// 竖版is_vertical = true;} else {// 横版is_vertical = false;}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return is_vertical;}


2、图片从不同服务器(网络)上获得


import com.itextpdf.text.Image;
// 图片属于网络上的地址try {String imagePath = "http://g.hiphotos.baidu.com/baike/c0%3Dbaike180%2C5%2C5%2C180%2C60/sign=db5a49b475f08202399f996d2a929088/8ad4b31c8701a18bf1c7bfd8982f07082838fe7d.jpg";Image img = Image.getInstance(new URL(imagePath));System.out.println("width=" + img.getWidth() + "-----------height="+ img.getHeight());} catch (Exception e) {e.printStackTrace();}

结果是:

width=1000.0-----------height=1486.0





0 0
原创粉丝点击