exif 인터페이스는 내 애플리케이션에서 Android에서 카메라 의도를 사용하여 캡처 한 저장된 이미지에 새로운 데이터를 쓰는 데 사용됩니다.업데이트 된 이미지를 갤러리로 출력하는 방법은 무엇입니까?
문제는 이미지 파일을 저장소로 출력 할 때 갤러리의 이미지 details
을 볼 때 이미지의 특성을 업데이트하는 코드가 실제로 저장된 이미지를 업데이트하지 않는다는 것입니다.
예를 들어 UserComment
태그를 사용하여 일부 일반 텍스트를 테스트 입력으로 추가하지만이 정보는 장치의 이미지 세부 정보에 표시되지 않습니다.
제 질문은 데이터가 실제로 파일에 기록되는지 어떻게 확인할 수 있습니까?
속성이 이미지에 추가되는 것을 알고 있다면 파일 저장소를 문제로 디버깅 할 수 있습니다.
이 프로젝트의 디렉토리에 마지막으로 캡처 한 이미지를 검색하는 getOutputPhotoFile()
방법 :
private File getOutputPhotoFile() throws IOException {
File directory = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), getPackageName());
if (!directory.exists()) {
if (!directory.mkdirs()) {
Log.e(TAG, "Failed to create storage directory.");
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
File[] files = directory.listFiles();
File origFile = new File(directory.getPath(), "IMG_" + timeStamp + ".jpg");
if(files.length!=0) {
File newestFile = files[files.length-1];
origFile = new File(directory.getPath() + File.separator + newestFile.getName());
}
String mString = "Generic Text..";
ExifInterface exifFile = new ExifInterface(origFile.getAbsolutePath());
exifFile.setAttribute("UserComment", mString);
exifFile.setAttribute(ExifInterface.TAG_GPS_LATITUDE,
String.valueOf(latituteField.toString()));
exifFile.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,
String.valueOf(longitudeField.toString()));
exifFile.saveAttributes();
return origFile;
}
첫 번째 API 호출에서 오타가 될 수 있습니다. –