目前共有4篇帖子。 字體大小:較小 - 100% (默認)▼  內容轉換:台灣正體▼
 
點擊 回復
133 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)
 

本帖信息

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