設置 | 登錄 | 註冊

目前共有4篇帖子。

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)

內容轉換:

回覆帖子
內容:
用戶名: 您目前是匿名發表。
驗證碼:
看不清?換一張
©2010-2025 Purasbar Ver3.0 [手機版] [桌面版]
除非另有聲明,本站採用知識共享署名-相同方式共享 3.0 Unported許可協議進行許可。