android
안드로이드(Android) 사진의 EXIF 정보 가져오기
관절분리
2016. 5. 16. 09:54
반응형
안드로이드(Android) 사진의 EXIF 정보 가져오기
개발환경 : window 7 64bit, Eclipse Mars, Android 4.2.2 |
EXIF 란 디지털 사진의 이미지 정보입니다. 아주 다양한 정보가 저장되는데 이미지의 기본값, 크기, 화소등이 있으며 사진을 찍은 카메라 정보, 찍을때 조리개, 노출정도등 이 저장됩니다. 이런 메타 정보들을 활용해서 앱을 만들고자 할 때 사용할수 있는 간단한 샘플입니다. |
먼저 이미지를 읽어오기 위해 에뮬레이터에 하나
추가합니다. 그리고 이미지를 읽어온뒤
ExifInterface 객체를 하나 만들어서 인수로 이미지
주소를 넘깁니다
1
2
3
4
5
6
7
8 |
String filename = Environment.getExternalStorageDirectory().getPath() + "/20140705_162816.jpg" ; try { ExifInterface exif = new ExifInterface(filename); showExif(exif); } catch (IOException e) { e.printStackTrace(); Toast.makeText( this , "Error!" , Toast.LENGTH_LONG).show(); } |
이렇게 넘어간 ExifInterface 객체를 가지고 구현한
showExif() 함수 입니다. getTagString() 함수를
사용하여 정보를 가져오는데 옵션값과 ExifInterface 객체를
인수값으로 넘깁니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
private void showExif(ExifInterface exif) { String myAttribute = "[Exif information] \n\n" ; myAttribute += getTagString(ExifInterface.TAG_DATETIME, exif); myAttribute += getTagString(ExifInterface.TAG_FLASH, exif); myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE, exif); myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE_REF, exif); myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE, exif); myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE_REF, exif); myAttribute += getTagString(ExifInterface.TAG_IMAGE_LENGTH, exif); myAttribute += getTagString(ExifInterface.TAG_IMAGE_WIDTH, exif); myAttribute += getTagString(ExifInterface.TAG_MAKE, exif); myAttribute += getTagString(ExifInterface.TAG_MODEL, exif); myAttribute += getTagString(ExifInterface.TAG_ORIENTATION, exif); myAttribute += getTagString(ExifInterface.TAG_WHITE_BALANCE, exif); mView.setText(myAttribute); } |
ExifInterface 의 옵션값은 소스에 있는 것 외에
많이 있으니 다른것들도 추가해서 구현해
보시기 바랍니다.
Exif Information 을 구현한 전체 메인 Activity 의 소스입니다.
메인 레이아웃 xml 은 간단해서 넣지 않았습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 |
import java.io.IOException; import android.app.Activity; import android.media.ExifInterface; import android.os.Bundle; import android.os.Environment; import android.widget.TextView; import android.widget.Toast; public class SampleActivity24 extends Activity { private TextView mView; @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_sample_activity24); mView = (TextView) findViewById(R.id.textview); String filename = Environment.getExternalStorageDirectory() .getPath() + "/20140705_162816.jpg" ; try { ExifInterface exif = new ExifInterface(filename); showExif(exif); } catch (IOException e) { e.printStackTrace(); Toast.makeText( this , "Error!" , Toast.LENGTH_LONG).show(); } } private void showExif(ExifInterface exif) { String myAttribute = "[Exif information] \n\n" ; myAttribute += getTagString(ExifInterface.TAG_DATETIME, exif); myAttribute += getTagString(ExifInterface.TAG_FLASH, exif); myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE, exif); myAttribute += getTagString( ExifInterface.TAG_GPS_LATITUDE_REF, exif); myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE, exif); myAttribute += getTagString( ExifInterface.TAG_GPS_LONGITUDE_REF, exif); myAttribute += getTagString(ExifInterface.TAG_IMAGE_LENGTH, exif); myAttribute += getTagString(ExifInterface.TAG_IMAGE_WIDTH, exif); myAttribute += getTagString(ExifInterface.TAG_MAKE, exif); myAttribute += getTagString(ExifInterface.TAG_MODEL, exif); myAttribute += getTagString(ExifInterface.TAG_ORIENTATION, exif); myAttribute += getTagString(ExifInterface.TAG_WHITE_BALANCE, exif); mView.setText(myAttribute); } private String getTagString(String tag, ExifInterface exif) { return (tag + " : " + exif.getAttribute(tag) + "\n" ); } } |
반응형