Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I'm trying to save exif data to an image captured by the device's camera but the data is not being written to the output image.

The image is re loaded sucesfully into an imageview after its captured so don't think its the incorrect image path that causes the problem.

Does anyone know why the data isn't being written to the image?


This is the method where the data is being written out to the image:

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; 
		  
		  
		  
		  
	}
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jan-15 15:26pm    
You only show the code where you set EXIF properties, never show where you use this object.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900