我正在尝试获取 jpeg 图像的 exif,但它不起作用。首先,我使用 BufferedImage 读取图像并将其转换为文件,然后应用与此处相同的代码:https ://code.google.com/p/metadata-extractor/source/browse/Samples/com/drew/元数据/SampleUsage.java?name=2.5.1。我究竟做错了什么?为什么 JpegSegmentReader.SEGMENT_APP1 返回 null?
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);
}