2015-01-01 12 views
11

मैं exif इंटरफ़ेस का उपयोग कर एंड्रॉइड एप्लिकेशन में एक कैप्चर की गई छवि में User_Comment और TAG_GPS लिखने की कोशिश कर रहा हूं, लेकिन किसी कारण से टैग गैलरी में छवि के विवरण देखने पर छवि में शामिल नहीं लगते हैं ।Android में छवि के लिए exif डेटा कैसे लिखें?

ऐसा लगता है कि हो सकता है कि टैग कैप्चर की गई छवि पर नहीं लिखे जा रहे हैं क्योंकि फ़ाइल पथ गलत हो सकता है। मुझे लगता है कि ऐसा इसलिए हो सकता है क्योंकि मैंने टैग को गलत छवि पथ में लिखा है।

क्या किसी को पता है कि क्या वे छवि में टैग लिखने के तरीके में कोई समस्या है?

private File getOutputPhotoFile() throws IOException { 
      File directory = new File(Environment.getExternalStoragePublicDirectory(
         Environment.DIRECTORY_PICTURES), getPackageName()); 
      if (!directory.exists()) { 
      if (!directory.mkdirs()) { 
       Log.e(TAG, "Failed to create storage directory."); 
       return null; 
      } 
      } 


      String timeStamp = new SimpleDateFormat("yyyMMdd_HHmmss", Locale.ENGLISH).format(new Date()); 

      File[] files = directory.listFiles(); 

      File exifVar = new File(directory.getPath(), "IMG_" + timeStamp + ".jpg"); 
      if(files.length!=0) { 
       File newestFile = files[files.length-1]; 
       exifVar = new File(directory.getPath() + File.separator + newestFile.getName()); 
      } 

      String mString = "Generic Text..";  
      ExifInterface exif = new ExifInterface(exifVar.getAbsolutePath()); 
      exif.setAttribute("UserComment", mString); 
      exif.saveAttributes(); 


      exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, 
      String.valueOf(latituteField.toString())); 

      exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, 
      String.valueOf(longitudeField.toString())); 

      exif.saveAttributes(); 

      return exifVar; 




    } 
+0

आप exif.saveAttributes को कई बार क्यों कॉल कर रहे हैं? मेरा मानना ​​है कि हर बार एक नई छवि बनाता है। बस सोच रहा है – wkhatch

+0

यह संभव है, मैंने थोड़ी देर में इस परियोजना पर काम नहीं किया है, मुझे लगता है कि समस्या यह हो सकती है कि डेटा "exif" नामक एक अस्थायी छवि में सहेजा जा रहा है और इसे कभी भी मूल छवि में नहीं लिखा गया है। –

उत्तर

3

आप exifVar.toString() उपयोग कर रहे हैं:

इस कोड है कि नीचे चार्ली परिवर्तन @ निम्नलिखित EXIF ​​डेटा बचाता है। यह सिर्फ फ़ाइल नाम देता है, छवि के पथ नहीं। चूंकि आपका ऐप शायद चित्रों वाले फ़ोल्डर में नहीं है, तो आपको exifVar.getAbsolutePath() का उपयोग करना चाहिए।

यदि आप एक ही समय में तस्वीर नहीं ले रहे हैं तो आप प्रोग्राम चला रहे हैं, पथ सही नहीं होगा।

File[] files = directory.listFiles(); 

if(files.length==0) { 
    // No images available 
    return; 
} 

File newestFile = files[files.length-1]; 

File exifVar = new File(directory.getPath() + File.separator + newestFile.getName()); 

ऑफ विषय:: बजाय इस कोड का उपयोग

अपने विशाल आयात सूची के अनुसार:

import android.content.*; 

आयात

android.content.Context, 
android.content.DialogInterface and 
android.content.Intent 

अपने कोड काफ़ी कम करता है यही कारण है कि । बस

+0

उपरोक्त परिवर्तनों के बाद भी एक्फिफ़ डेटा छवि विवरण में जोड़ा नहीं जाता है, क्या आपके पास कोई विचार है? –

3

कह आप exif यहाँ google exif अपने प्रोजेक्ट में स्थित फ़ाइलों की प्रतिलिपि बनाने, उसके बाद निम्न कोड का उपयोग पहले की जरूरत है:

ExifInterface exif = new ExifInterface(); 
exifi.readExif(exifVar.getAbsolutePath()); 
exif.setTagValue(ExifInterface.TAG_USER_COMMENT, mString); 
exif.forceRewriteExif(exifVar.getAbsolutePath())); 

यहां इस्तेमाल किया ExifInterface नया एक तुम सिर्फ जोड़ दिया है।

+0

यह बेहतर होगा यदि आप डेटा प्रकार और वैरिएबल "exifi" के प्रारंभिकरण निर्दिष्ट कर सकते हैं – Deva

संबंधित मुद्दे