2017-03-16 35 views
0

我試圖刪除一個標記,以便能夠重新添加一個更正的值。有問題的exif標籤是:GPSImgDirection,但它似乎並沒有保存新的值(我猜這不是刪除/找到標籤)替換GPS標記值[編輯EXIF]

我究竟做錯了什麼?我一直在試圖從apache(WriteExifMetadataExample.java)跟蹤示例文件。

P.S.我設置的恆定值的合理值,以簡化代碼的例子...

public static void setBearing(File f, Double bearing) 
    throws IOException, ImageReadException, ImageWriteException{ 

    try (FileOutputStream fos = new FileOutputStream(f.getParent()+ File.separator+"SUPERTMPDUMP12324231.jpg",false); 
      OutputStream os = new BufferedOutputStream(fos);) { 

     TiffOutputSet outputSet = null; 

     final ImageMetadata metadata = Imaging.getMetadata(new File(f.getAbsolutePath())); 
     final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; 
     if (null != jpegMetadata) { 
      final TiffImageMetadata exif = jpegMetadata.getExif(); 

      if (null != exif) { 
       outputSet = exif.getOutputSet(); 
      } 
     } 

     if (null == outputSet) { 
      outputSet = new TiffOutputSet(); 
     } 

     Rational r = new Rational(bearing);  
     final TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory(); 

     exifDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); 
     exifDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, new RationalNumber(454349, 10000)); 


     new ExifRewriter().updateExifMetadataLossless(f, os, 
       outputSet); 
     //Replace file with new meta data 
     Files.move(Paths.get(f.getPath()+ File.separator+"SUPERTMPDUMP12324231.jpg"), Paths.get(f.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING); 
    } 

} 

回答

0

發現這個問題,因爲它是在「GPS」目錄,我需要:

final TiffOutputDirectory exifDirectory = outputSet.getOrCreateGPSDirectory(); 

,而不是

final TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory();