It stores the latitude and longitude value in a float array. The first element is the latitude, and the second element is the longitude. Returns false if the Exif tags are not available.
Example:
package com.AndroidExif;
import java.io.IOException;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class AndroidExifActivity extends Activity {
String imagefile ="/sdcard/DCIM/DSC_9599.jpg";
ImageView image;
TextView Exif;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView)findViewById(R.id.image);
Exif = (TextView)findViewById(R.id.exif);
ImageView image = (ImageView)findViewById(R.id.image);
Bitmap bm = BitmapFactory.decodeFile(imagefile);
image.setImageBitmap(bm);
Exif.setText(ReadExif(imagefile));
}
String ReadExif(String file){
String exif="Exif: " + file;
try {
ExifInterface exifInterface = new ExifInterface(file);
exif += "\nIMAGE_LENGTH: " + exifInterface.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
exif += "\nIMAGE_WIDTH: " + exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
exif += "\n DATETIME: " + exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
exif += "\n TAG_MAKE: " + exifInterface.getAttribute(ExifInterface.TAG_MAKE);
exif += "\n TAG_MODEL: " + exifInterface.getAttribute(ExifInterface.TAG_MODEL);
exif += "\n TAG_ORIENTATION: " + exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);
exif += "\n TAG_WHITE_BALANCE: " + exifInterface.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
exif += "\n TAG_FOCAL_LENGTH: " + exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
exif += "\n TAG_FLASH: " + exifInterface.getAttribute(ExifInterface.TAG_FLASH);
exif += "\nGPS related:";
float[] LatLong = new float[2];
if(exifInterface.getLatLong(LatLong)){
exif += "\n latitude= " + LatLong[0];
exif += "\n longitude= " + LatLong[1];
}else{
exif += "Exif tags are not available!";
}
Toast.makeText(AndroidExifActivity.this,
"finished",
Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(AndroidExifActivity.this,
e.toString(),
Toast.LENGTH_LONG).show();
}
return exif;
}
}
next post:
- Set latitude and longitude in Exif, setAttribute() and saveAttributes().
No comments:
Post a Comment