`
maxwell
  • 浏览: 64876 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Java 读取 JPEG 文件的 exif 信息

阅读更多
突然要用Java 读取 JPEG文件的信息, 宽度, 高度, 颜色表示等信息。

下载了一个工具jar 包 metadata-extractor-2.3.1.jar , 网上搜一下 放到lib 里面。

一个简单的类来读取信息
ReadFileProperties.java

package com.founder.readfile;
import java.io.File;
import java.util.Iterator;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.drew.metadata.exif.ExifDirectory;

public class ReadFileProperties {
public static void main(String[] args) throws Exception {
        File jpegFile = new File("E:/pic/LOGO.jpg");
        Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
        Directory exif = metadata.getDirectory(ExifDirectory.class);
        Iterator tags = exif.getTagIterator();
        // print color space
        if(exif.containsTag(ExifDirectory.TAG_COLOR_SPACE)){
            System.out.println("color space = " +  exif.getDescription(ExifDirectory.TAG_COLOR_SPACE));
        }
        //print all exif metadata
        while (tags.hasNext()) {
            Tag tag = (Tag)tags.next();
            System.out.println(tag.getTagType() + "====>" +tag);
        }
    }
}
留下 备忘。
分享到:
评论
1 楼 wangbaosong09 2011-03-03  
你好。我的输出怎么什么也没有?
还有我想问下:java中能么读出JPG图像的码流信息,比如宽和高,颜色信息等。我需要这些值做图像处理。谢谢!

相关推荐

Global site tag (gtag.js) - Google Analytics