2012년 6월 20일 수요일

Exif 헤더 수정 (Image 관련 헤더)




안드로이드는 다행스럽게도 이미지 해더를 수정할수 있는 클레스를 제공해준다. 문론 아이폰도 동일하다.


ExifInterface 란 이름이고 사용법은 매우 간단하다.


ExifInterface exif = new ExifInterface(filePath);
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, latitude);
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, longitude);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, orientation);
exif.saveAttributes();


저렇게 클레스를 선언하고 파일경로만 선언하고 수정할 해더 정보를 수정하면 된다. 기본적으로 width나 height 정보는 지정하지 않아도 자동으로 세팅 된다.
태그 정보는 아래 주소 참조. http://developer.android.com/reference/android/media/ExifInterface.html


변경하고 싶은 테그 속성을 변경하고 saveAttributes()를 실행하면 수정 끝..


주의사항은 GPS 좌표를 변경할때 포멧에 맞지 않는 정보를 넣으면 기본 갤러리에서 에러를 발생할수 있다.
public static String ConvertTagGPSFormat(double coordinate) {

   if (coordinate < -180.0 || coordinate > 180.0 || Double.isNaN(coordinate)) {
      throw new IllegalArgumentException("coordinate=" + coordinate);
   }


   StringBuilder sb = new StringBuilder();


   if (coordinate < 0) {
      sb.append('-');
      coordinate = -coordinate;
   }

   int degrees = (int) Math.floor(coordinate);
   sb.append(degrees);
   sb.append("/1,");
   coordinate -= degrees;
   coordinate *= 60.0;
   int minutes = (int) Math.floor(coordinate);
   sb.append(minutes);
   sb.append("/1,");
   coordinate -= minutes;
   coordinate *= 60.0;
   sb.append(coordinate);
   sb.append("/1000");


   return sb.toString();
}


이런식으로 location에 담겨있는 정보를 택스트 형식으로 변경하여 저장하면 문제 없이 저장된다.


출처 : http://blog.naver.com/anywars/140132767414

댓글 없음:

댓글 쓰기