In the development of Android development
In the development of Android development
ExiFinterface is a framework provided by the Android platform to process image metadata.Through ExiFinterface, developers can read and modify the metadata information of the picture, including shooting equipment, shooting time, focal length, exposure time, and so on.This article will answer some questions that are often seen using the EXIFINTERFACE framework in Android development.
1. How to get the EXIF information of the picture?
To obtain the EXIF information of the picture, you need to use the ExiFinterface class and pass the path of the picture.Here are a sample code for obtaining pictures EXIF information:
String imagePath = "/sdcard/Pictures/example.jpg";
ExifInterface exif = new ExifInterface(imagePath);
String exifData = exif.getAttribute(ExifInterface.TAG_MODEL);
In the above code, we can obtain the EXIF information of the picture by creating an ExiFinterface object and passing the path of the picture.We then use the gettattribute () method to pass the constant defined in an ExiFinterface, such as tag_model to obtain the shooting equipment information of the picture.You can get other EXIF information as needed.
2. How to modify the EXIF information of the picture?
To modify the EXIF information of the picture, you can use the settattribute () method of the ExiFinterface class.Here are a sample code that modifys the EXIF information:
String imagePath = "/sdcard/Pictures/example.jpg";
ExifInterface exif = new ExifInterface(imagePath);
exif.setAttribute(ExifInterface.TAG_MODEL, "New Camera Model");
exif.saveAttributes();
In the above code, we can obtain the EXIF information of the picture by creating an ExiFinterface object and passing the path of the picture.We then use the settattribute () method to pass the constant defined in an ExiFinterface, such as tag_model to modify the shooting equipment information of the picture.Finally, we call the saveattributes () method to save the modified EXIF information.
3. How to configure read and write exif permissions in AndroidManifest.xml?
To read and write the EXIF information of the picture, you need to add the next authority to the Androidmanifest.xml file:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
In the above code, we added read_external_storage permissions to read pictures in the memory, as well as WRITE_EXTERNAL_STORAGE permissions used to modify pictures in the memory.Please note that starting with Android 6.0 (API Level 23), you also need to apply for these permissions at runtime.
Summarize
This article briefly introduces the common problems when using the ExiFinterface framework in Android development.We understand how to get the EXIF information of the picture, how to modify the EXIF information of the picture, and how to configure read and write the exif permissions in Androidmanifest.xml.By using the ExiFinterface framework reasonably, we can easily process and modify the metadata information of the picture to meet various needs.