Read Exif info

With ExifInterface, you can read various TAGs from Exif in JPG files; such as APERTURE, EXPOSURE_TIME, FOCAL_LENGTH, ISO, WHITE_BALANCE, FLASH, MODEL, DATETIME, GPS...etc. Please note that the higher target API level support the more TAGs.

Read Exif info


Modify from onItemClick() method of photoBarOnItemClickListener in last post "Implement AdapterView.OnItemClickListener for Gallery" to read Exif TAGS.

 OnItemClickListener photoBarOnItemClickListener
= new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {

String itemInfo = ((PhotoItem)(parent.getItemAtPosition(position))).bitmapImageSrc;

Toast.makeText(AndroidGalleryActivity.this,
"Clicked item:\n" + itemInfo,
Toast.LENGTH_LONG).show();

ExifInterface exif = ((PhotoItem)(parent.getItemAtPosition(position))).exifInterface;
AlertDialog.Builder exifDialog = new AlertDialog.Builder(AndroidGalleryActivity.this);
exifDialog.setTitle("Exif info:");

String exifInfo =
"APERTURE: " + exif.getAttribute(ExifInterface.TAG_APERTURE) + "\n" +
"EXPOSURE_TIME: " + exif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME) + "\n" +
"FOCAL_LENGTH: " + exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH) + "\n" +
"ISO: " + exif.getAttribute(ExifInterface.TAG_ISO) + "\n" +
"WHITE_BALANCE: " + exif.getAttribute(ExifInterface.TAG_WHITE_BALANCE) + "\n" +
"FLASH: " + exif.getAttribute(ExifInterface.TAG_FLASH) + "\n" +
"MAKE: " + exif.getAttribute(ExifInterface.TAG_MAKE) + "\n" +
"MODEL: " + exif.getAttribute(ExifInterface.TAG_MODEL) + "\n" +
"GPS_LATITUDE_REF: " + exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF) + "\n" +
"GPS_LATITUDE: " + exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) + "\n" +
"GPS_LONGITUDE_REF: " + exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF) + "\n" +
"GPS_LONGITUDE: " + exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) + "\n" +
"DATETIME: " + exif.getAttribute(ExifInterface.TAG_DATETIME);

TextView textExifInfo = new TextView(AndroidGalleryActivity.this);
textExifInfo.setText(exifInfo);
LayoutParams textOutLayoutParams
= new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
textExifInfo.setLayoutParams(textOutLayoutParams);

LinearLayout dialogLayout = new LinearLayout(AndroidGalleryActivity.this);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
dialogLayout.addView(textExifInfo);
exifDialog.setView(dialogLayout);

exifDialog.setPositiveButton("OK", null);

exifDialog.show();

}

};


0 Response to "Read Exif info"

Posting Komentar