Java获取获取exif信息_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Java获取获取exif信息

Java获取获取exif信息

 2018/11/8 21:27:44  wedtlcy  程序员俱乐部  我要评论(0)
  • 摘要:/***@Description:判断图片是否被PS过*@Param:[picPath]*@return:java.lang.String*@Author:chuanyin.li*@Date:2018/11/8*/publicstaticStringisPsFlag(StringpicPath){StringisPsFlag="0";try{FilejpegFile=newFile(picPath);Metadatametadata=JpegMetadataReader
  • 标签: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);
}

  }
  • metadata-extractor-2.3.1.jar (86.7 KB)
  • 下载次数: 0
  • mediautil-1.0.jar (117 KB)
  • 下载次数: 0
上一篇: C# 复制Excel工作表 下一篇: 没有下一篇了!
发表评论
用户名: 匿名