`
wedtlcy
  • 浏览: 23312 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

Java获取获取exif信息

    博客分类:
  • Java
阅读更多
/** 
* @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);
}

  }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics