2013-11-22 60 views
1

我想要的.jpg &的.tif使用JAVA 任何一個可以幫助我的示例文件的更新元數據(如標籤,註釋等....)....如何更新jpg的元數據值,在JAVA中的tiff文件?

我有做相同使用的docx文件的Apache POI

 OPCPackage opc = OPCPackage.open("metadata.docx"); 
     PackageProperties pp = opc.getPackageProperties(); 

     Nullable<String> foo = pp.getLastModifiedByProperty(); 
     System.out.println(foo.hasValue()?foo.getValue():"empty"); 
     //Set some properties 
     pp.setCreatorProperty("M Kazarian"); 
     pp.setLastModifiedByProperty("M Kazarian " + System.currentTimeMillis()); 
     pp.setModifiedProperty(new Nullable<Date>(new Date())); 
     pp.setTitleProperty("M Kazarian document"); 

記:那麼PLZ提到,我應該下載&進口來更新元數據的罐子。

在此先感謝....

+0

[Java元數據讀寫]的可能重複(http://stackoverflow.com/questions/16895251/java-metadata-read-and-write) – Blacklight

+0

實際上我想更新元數據的值 – user2959944

+0

更新方式閱讀和寫作,還是我誤解了一些東西? – Blacklight

回答

0

嘗試使用commons imaging

Here是如何更新JPEG元數據的例子:

public void changeExifMetadata(final File jpegImageFile, final File dst) 
     throws IOException, ImageReadException, ImageWriteException { 
    OutputStream os = null; 
    boolean canThrow = false; 
    try { 
     TiffOutputSet outputSet = null; 

     final IImageMetadata metadata = Imaging.getMetadata(jpegImageFile); 
     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(); 
     } 

     { 
      final TiffOutputDirectory exifDirectory = outputSet 
        .getOrCreateExifDirectory(); 
      exifDirectory 
        .removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE); 
      exifDirectory.add(ExifTagConstants.EXIF_TAG_APERTURE_VALUE, 
        RationalNumber.factoryMethod(3, 10)); 
     } 

     { 
      final double longitude = -74.0; 
      final double latitude = 40 + 43/60.0; 

      outputSet.setGPSInDegrees(longitude, latitude); 
     } 

     os = new FileOutputStream(dst); 
     os = new BufferedOutputStream(os); 

     new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, 
       outputSet); 

     canThrow = true; 
    } finally { 
     IoUtils.closeQuietly(canThrow, os); 
    } 
} 
+0

如何更改標題值.....? – user2959944

0

javax.imageio.metadata中包含元數據相關的類。 IIOMetadata類對您很有用。嘗試使用ImageWriter類中的方法

write(IIOMetadata streamMetadata,IIOImage image,ImageWriteParam param) 

方法。