目前共有4篇帖子。 字體大小:較小 - 100% (默認)▼  內容轉換:不轉換▼
 
點擊 回復
176 3
Java判断手机拍摄的照片是否有翻转标志
一派掌門 二十級
1樓 發表于:2024-10-14 17:26

去下面的网址下载metadata-extractor-2.6.2.jar和xmpcore-5.1.2.jar两个jar包:

https://mvnrepository.com/artifact/com.drewnoakes/metadata-extractor/2.6.2
https://mvnrepository.com/artifact/com.adobe.xmp/xmpcore/5.1.2

经测试,这两个jar包都支持Java 6。下载后导入eclipse项目。


【测试代码】

package test;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.MetadataException;
import com.drew.metadata.Tag;

public class JPGTest {

 public static void main(String[] args) {
  test("E:\\用户的文档\\Octopus\\Documents\\WeChat Files\\wxid_z90coebc6md122\\FileStorage\\File\\2024-10\\IMG_20240921_122601_1\\IMG_20240921_122601_1.jpg");
 }
 
 private static void test(String filename) {
  try {
   File file = new File(filename);
   Metadata metadata = ImageMetadataReader.readMetadata(file);
   Iterable<Directory> directories = metadata.getDirectories();
   for (Directory directory : directories) {
    String name = directory.getName();
    if (name.equals("Exif IFD0")) {
     Collection<Tag> tags = directory.getTags();
     for (Tag tag : tags) {
      name = tag.getTagName();
      if (name.equals("Orientation")) {
       int type = tag.getTagType();
       System.out.println("Tag type: " + type);
       int value = directory.getInt(type);
       System.out.println("Tag value: " + value);
       String desc = tag.getDescription();
       System.out.println("Tag description: " + desc);
      }
     }
    }
   }
  } catch (JpegProcessingException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } catch (ImageProcessingException e) {
   e.printStackTrace();
  } catch (MetadataException e) {
   e.printStackTrace();
  }
 }
}


【输出结果】

Tag type: 274
Tag value: 6
Tag description: Right side, top (Rotate 90 CW)


CW代表顺时针方向旋转。‌ CW是clockwise的缩写,表示顺时针旋转。

‌CCW代表逆时针方向旋转。‌ CCW是counterclockwise的缩写,表示逆时针旋转。

Rotate 90 CW表示顺时针旋转90度。

一派掌門 二十級
2樓 發表于:2024-10-14 17:31

github里面也可以下载
https://github.com/drewnoakes/metadata-extractor/releases?page=3
文件名为metadata-extractor-2.6.2.zip。

压缩包里面是metadata-extractor-2.6.2.jar和xmpcore.jar。(xmpcore文件名没有标注版本号)

压缩包注释:Metadata Extractor - http://drewnoakes.com/code/exif/

 
一派掌門 二十級
3樓 發表于:2024-10-14 17:34
Tag value一共有8种值,如下图所示。
 
一派掌門 二十級
4樓 發表于:2024-10-14 17:40

8种取值的描述:

(1)Top, left side (Horizontal / normal)
(2)Top, right side (Mirror horizontal)
(3)Bottom, right side (Rotate 180)
(4)Bottom, left side (Mirror vertical)
(5)Left side, top (Mirror horizontal and rotate 270 CW)
(6)Right side, top (Rotate 90 CW)
(7)Right side, bottom (Mirror horizontal and rotate 90 CW)
(8)Left side, bottom (Rotate 270 CW)

 

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:176 回複數:3
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2024-10-14 17:40
 
©2010-2025 Purasbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。