Code example for ExifInterface

Methods: getAltitude, getAttribute

1
  /*¨ú±oEXIF¸ê°T¨ÃÅã¥Ü©óTextViewªºmethod*/ 
  private void ShowExif()  
  {  
    try 
    { 
      ExifInterface exif = new ExifInterface(filename);
      StringBuffer tmp=new StringBuffer();
      tmp.append("====== Exif information ======\n");
      tmp.append(getExifContent(ExifInterface.TAG_DATETIME,exif)); 
      tmp.append(getExifContent(ExifInterface.TAG_MAKE,exif)); 
      tmp.append(getExifContent(ExifInterface.TAG_MODEL,exif)); 
      tmp.append(getExifContent(ExifInterface.TAG_IMAGE_WIDTH,exif));
      tmp.append(getExifContent(ExifInterface.TAG_IMAGE_LENGTH,exif));  
      tmp.append(getExifContent(ExifInterface.TAG_WHITE_BALANCE,exif));
      tmp.append(getExifContent(ExifInterface.TAG_FLASH,exif)); 
      tmp.append(getExifContent(ExifInterface.TAG_FOCAL_LENGTH,exif)); 
      tmp.append(getExifContent(ExifInterface.TAG_ORIENTATION,exif)); 
      tmp.append(getExifContent(ExifInterface.TAG_GPS_LATITUDE,exif));   
      tmp.append(getExifContent(ExifInterface.TAG_GPS_LONGITUDE,exif)); 
      tmp.append(getExifContent(ExifInterface.TAG_GPS_ALTITUDE,exif));
      tmp.append("getAltitude() : "+exif.getAltitude(10.00));
      textView1.setText(tmp.toString());
    } 
    catch (IOException e)
    { 
      e.printStackTrace();
    } 
  }  
   
  /*½Æ¼gEXIF¸ê°Tªºmethod*/ 
  private void WriteExif() 
  { 
    try 
    { 
      ExifInterface exif = new ExifInterface(filename);
      exif.setAttribute(ExifInterface.TAG_DATETIME, "2011:01:01 01:01:01");
      exif.setAttribute(ExifInterface.TAG_MAKE, "Panasonic");
      exif.setAttribute(ExifInterface.TAG_MODEL, "Panasonic LX5");
      exif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, "1024");
      exif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, "768");
      exif.setAttribute(ExifInterface.TAG_WHITE_BALANCE, "0");
      exif.setAttribute(ExifInterface.TAG_FLASH, "1");
      exif.setAttribute(ExifInterface.TAG_FOCAL_LENGTH, "200/100");
      exif.setAttribute(ExifInterface.TAG_ORIENTATION, "0");
      exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, "25/1,4/1,2000/100");
      exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, "121/1,34/1,3000/100");
      exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, "50/1");
      /*Àx¦s½Æ¼gªº¸ê°T*/ 
      exif.saveAttributes();
    } 
    catch (IOException e)
    { 
      e.printStackTrace();
    } 
  } 
     
  /*¨ú±oEXIF¤º®eªºmethod*/ 
  private String getExifContent(String tagName,ExifInterface exif) 
  { 
    return(tagName+" : "+exif.getAttribute(tagName)+"\n"); 
  }   
}