我想獲得一個jpeg圖像的exif,但它不起作用。首先,我使用BufferedImage讀取圖像,然後將其轉換爲文件,然後應用與此處相同的代碼:https://code.google.com/p/metadata-extractor/source/browse/Samples/com/drew/metadata/SampleUsage.java?name=2.5.1。我究竟做錯了什麼?爲什麼JpegSegmentReader.SEGMENT_APP1返回null?元數據提取java沒有提取exif或iptc
File outfile = new File("image.jpg");
ImageIO.write(imagine, "jpg", outfile);
try{
JpegSegmentReader segmentReader = new JpegSegmentReader(outfile);
byte[] exifSegment = segmentReader.readSegment(JpegSegmentReader.SEGMENT_APP1);
System.out.println(Arrays.toString(segmentReader.readSegment(JpegSegmentReader.SEGMENT_APP1)));
byte[] iptcSegment = segmentReader.readSegment(JpegSegmentReader.SEGMENT_APPD);
Metadata metadata = new Metadata();
if (exifSegment != null)
new ExifReader().extract(new ByteArrayReader(exifSegment), metadata);
if (iptcSegment != null)
new IptcReader().extract(new ByteArrayReader(iptcSegment), metadata);
printImageTags(metadata);
}catch (JpegProcessingException e) {
System.err.println("error 3a: " + e);
}