2012-08-23 4 views
3

갤러리의 이미지와 관련된 모든 exif 속성을 나열하려고합니다. 모든 getAttribute()는 null을 반환합니다. 내가 디버그하고 ExifInterface를 검사 할 때 그것은 유효한 파일을 가지고 있으며 "mAttributes"노드를 확장하면 "테이블"에 내가 찾고있는 EXIF ​​데이터가 모두 들어 있지만 "값", "keySet"및 "valuescollection "는 null입니다. 내가 잘못 가고있는 어떤 생각?EXIF ​​getAttributes return null

편집 : 아마도 파일 이름을 얻는 방법에 문제가있을 것입니다. 좀 더 완벽한 그림을 제공하기 위해 아래 코드를 업데이트했습니다.

//create an array of thumbnail IDs 
String[] ids = {MediaStore.Images.Thumbnails._ID}; 
//this pulls the file locations 
cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ids, null, null, MediaStore.Images.Thumbnails.IMAGE_ID); 
colIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID); 

//at this point we need to target the gridview. 
GridView gallery = (GridView) findViewById(R.id.gridView1); 
//borrowed an adapter provided in the tutorial at http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html 
gallery.setAdapter(new ImageAdapter(this)); 

//now we attach a listener to our gridview. 
gallery.setOnItemClickListener(new OnItemClickListener(){ 
    public void onItemClick(AdapterView parent, View v, int position, long id) 
    { 
     String[] ids = {MediaStore.Images.Media.DATA}; 
     cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, ids, null, null, null); 
     colIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
     cursor.moveToPosition(position); 
     String image = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); 
     ExifInterface clicked = null; 
     try { 
      clicked = new ExifInterface(image); 
    } catch (IOException e) { 
      // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

     if(clicked==null) 
     { 
     Toast.makeText(getApplicationContext() , "We were not able to load the file." , Toast.LENGTH_LONG).show(); 
     } 
     else 
     { 
     TextView tv = (TextView) findViewById(R.id.messageCenter); 
     String message; 
     message = "Latitude: " + clicked.getAttribute(ExifInterface.TAG_GPS_LATITUDE) + "\n"; 
     message += "Longitude: " + clicked.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) + "\n"; 
     message += "Make: " + clicked.getAttribute(ExifInterface.TAG_MAKE) + "\n"; 
     message += "Model: " + clicked.getAttribute(ExifInterface.TAG_MODEL) + "\n"; 
     message += "Date/Time: " + clicked.getAttribute(ExifInterface.TAG_DATETIME) + "\n"; 
     message += "Flash: " + clicked.getAttribute(ExifInterface.TAG_FLASH) + "\n"; 
     message += "Flocal Length: " + clicked.getAttribute(ExifInterface.TAG_FOCAL_LENGTH) + "\n"; 
     message += "White Balance: " + clicked.getAttribute(ExifInterface.TAG_WHITE_BALANCE); 

     tv.setText(message); 
    } 
} 
}); 

다음은 런타임에 enter image description here

편집 같은 외모를 클릭 무엇 : 내가 찾은 그 테이블 작품에 나열된 값을 호출. 그러나 mAttributes.table. [0] .value.value를 확장하면 찾고있는 다른 정보가 char 배열에 나열됩니다. 그 정보가 왜 전달되지 않는가?

+0

이것은 아마도 문제가 아니지만 그 상수는'clicked.TAG_GPS_LATITUDE' 대신'ExifInterface.TAG_GPS_LATITUDE'가되어서는 안됩니까? – kcoppock

+0

나는 그것을 또한 시도했다. 또한 상수의 값을 사용하여 시도 했으므로 TAG_MODEL의 값은 "모델"입니다. 거기에 주사위도 없습니다. – Billdr

답변

1

일부 사진이 제대로 작동하므로 문제는 데이터가 아니라 클래스 또는 코드입니다. 일부 장치/응용 프로그램 ExifInterface 구문 분석 할 수없는 표준이 아닌 방식으로 자신의 exif 데이터를 인코딩 할 것으로 판단됩니다.

+0

예. 구글 안드로이드 OS의 고통이다. – GreenRobo

2

이미지 편집에 사용하는 소프트웨어를 의심해야합니다. 그것이 단지 "뷰어"일지라도 다른 형식으로 저장하는 데 사용합니다. 일부는 EXIF를 조작하고 일부는 전부 제거합니다. 또한 EXIF가 표준이라고 생각할지라도 제조업체에서 태그를 얼마나 정확하게 구현하고 이름을 지정하는 지에 따라 제조업체마다 큰 차이가 있습니다. ExifTool이라는 도구가있어 EXIF를 덤프 할 수있을뿐 아니라 수정하고 표준화 할 수 있습니다. 어쩌면 그것을 당신의 프로세스 흐름에 삽입하거나 코드에서 호출 할 수 있습니다.