Java获取获取exif信息

/** * @Description: 判断图片是否被PS过 * @Param: [picPath] * @return: java.lang.String * @Author: chuanyin.li * @Date: 2018/11/8 */ public static String isPsFlag(Str...
/** 
* @Description: 判断图片是否被PS* @Param: [picPath] 
* @return: java.lang.String 
* @Author: chuanyin.li
* @Date: 2018/11/8 
*/ 
public static String isPsFlag(String picPath){
    String isPsFlag = "0";
    try {
        File jpegFile = new File(picPath);
Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
Directory exif = metadata.getDirectory(ExifDirectory.class);//这里要稍微注意下
Iterator tags = exif.getTagIterator();
        while (tags.hasNext()) {
            Tag tag = (Tag)tags.next();
System.out.println(tag+"==="+tag.getDirectoryName()+"====="+tag.getTagName()+"====="+tag.getDescription());
            if(tag.getDescription().contains("Adobe Photoshop"))
                isPsFlag = "1";
}
    } catch (Exception e) {
        e.printStackTrace();
}
    return isPsFlag;
}

/** 
* @Description: 获取文件 exif信息
* @Param: [exif] 
* @return: java.lang.String 
* @Author: chuanyin.li
* @Date: 2018/11/8 
*/ 
public static String getOrientationDescription(Directory exif) throws MetadataException {
      if (!exif.containsTag(ExifDirectory.TAG_ORIENTATION)) return null;
      int orientation = exif.getInt(ExifDirectory.TAG_ORIENTATION);
      switch (orientation) {
          case 1:
              return "Top, left side (Horizontal / normal)";
          case 2:
              return "Top, right side (Mirror horizontal)";
          case 3:
              return "Bottom, right side (Rotate 180)";
          case 4:
              return "Bottom, left side (Mirror vertical)";
          case 5:
              return "Left side, top (Mirror horizontal and rotate 270 CW)";
          case 6:
              return "Right side, top (Rotate 90 CW)";
          case 7:
              return "Right side, bottom (Mirror horizontal and rotate 90 CW)";
          case 8:
              return "Left side, bottom (Rotate 270 CW)";
          default:
              return String.valueOf(orientation);
}

  }

原文出处:http://wedtlcy.iteye.com/blog/2433519

  • 发表于 2018-11-09 13:59
  • 阅读 ( 515 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除