2010-07-14 35 views
13

我想在圖像中存儲一些元數據。我的相機應用程序爲我提供了一個位圖,該位圖存儲在存儲(MediaStore)設備中。除此之外,我想在其元數據中爲圖片添加一些標籤。我認爲EXIF是做這件事的好方法。但我無法找到如何做到這一點的好參考。將EXIF元數據寫入Android中的圖像

如果在Android編程中有一些工具可以實現這個任務,請告訴我。

謝謝

+1

ExifInterface答案可有些不可靠 - 我已經看到它在某些情況下損壞的EXIF數據。處理更多EXIF標籤(包括自定義EXIF標籤)的更可靠的選項是Sanselan Android。 http://code.google.com/p/sanselanandroid/ Sanselan Android的使用示例如下:http://massapi.com/source/sanselan-0.97-incubator/src/test/java/org/apache/sanselan/ sampleUsage/WriteExifMetadataExample.java.html – Theo 2012-12-09 03:02:47

+0

查看[this](https://github.com/dragon66/pixymeta-android) – dragon66 2015-03-30 20:15:04

回答

9

好吧,有人(離線)指出我有用的資源。 ExifInterface看起來像我正在尋找。 Android-er有一篇文章演示如何閱讀Android中的EXIF元數據,我認爲寫作不應該有很大的不同。

我不知道,但我們可以用EXIF寫任意的元數據,即。除了ExifInterface documentation(如經緯度,閃光燈等)中指定的以外。如果不是,那麼將任意元數據寫入圖像文件的首選方法是什麼?

感謝

+1

您能否從第2段中提出一個新問題,以便我們能夠正確回答它? (恕我直言,答案是肯定的) – MikeD 2013-04-09 08:31:00

+1

剛剛做到了:http://stackoverflow.com/questions/15901971/writing-arbitrary-metadata-to-exif-in-android – vpk 2013-04-09 12:32:23

+0

我也發現這個庫很有用:https:// github.com/dragon66/pixymeta-android – 2017-05-30 12:55:14

5
public static void writeFile (File photo, double latitude, double longitude) throws IOException{ 
    ExifInterface exif = null; 

    try{ 
     Log.v("latiDouble", ""+latitude); 
     Log.v("longiDouble", ""+longitude); 
     exif = new ExifInterface(photo.getCanonicalPath()); 
     if (exif != null) { 
      double latitu = latitude; 
      double longitu = longitude; 
      double alat = Math.abs(latitu); 
      double along = Math.abs(longitu); 
      String stringLati = convertDoubleIntoDegree(alat); 
      String stringLongi = convertDoubleIntoDegree(along); 
      exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, stringLati); 
      exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, stringLongi); 
      Log.v("latiString", ""+ stringLati); 
      Log.v("longiString", ""+ stringLongi); 
      exif.saveAttributes(); 
      String lati = exif.getAttribute (ExifInterface.TAG_GPS_LATITUDE); 
      String longi = exif.getAttribute (ExifInterface.TAG_GPS_LONGITUDE); 
      Log.v("latiResult", ""+ lati); 
      Log.v("longiResult", ""+ longi); 
     } 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

我複製從here