Android Pictures EXIF information related to get and modify

Source: Internet
Author: User

1 What is EXIF?

EXIF is an image file format, its data is stored in the JPEG format is exactly the same, in fact, the EXIF format is the JPEG format header inserted digital photo information, including the shooting aperture, shutter, balance white, ISO, focal length, date and time and other various and shooting conditions and camera brand, model, Color coding, GPS and so on. Simply put, exif= shooting parameters +jped. Therefore, you can use any view of the JPEG file viewing software to browse EXIF information, but not all graphics programs can handle EXIF information, and since Android2.0, added to the image EXIF data support.

2 Exifinterface Class Introduction

Under Android, the EXIF information of the picture is manipulated through the Exifinterface class, although the name of this class contains interface, but it is not an interface, it is a class, under the "Android.media.ExifInterface" package, is the implementation of a part of the Media Library feature. Exifinterface has a constructor that accepts a string type of data, which is the address of the image file to be read.

EXIF data in the picture can be understood as Key-value key-value pairs of the way to store, generally by the following several methods of operation:

String getattribute: Gets the string value of the property tag in the picture.

Double getattribute (String tag,double defaultvalue): Gets the double value of the property in the picture as tag.

int Getattributeint (String tag,defaultvalue): Gets the int value of the property in the picture as tag.

void SetAttribute (String tag,string value): Sets the value of the image EXIF according to the input parameters.

void Saveattrubutes (): Writes Exif of the in-memory picture to the picture.

3 on the Code

 Public classMainactivityextendsActivity {ArrayList<String> FileNames =NewArraylist<string> ();//Local picture PathString Imgpath; StringBuilder text=NewStringBuilder (); @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);            Setcontentview (R.layout.activity_main);    Filenames.clear (); Cursor Cursor= Getcontentresolver (). Query (Media.external_content_uri,NULL,NULL,NULL,NULL);  while(Cursor.movetonext ()) {byte[] data = Cursor.getblob (Cursor.getcolumnindex (media.data));//The data where the picture is savedFilenames.add (NewString (data, 0, data.length-1)); }        if(Filenames.size () > 0) {Imgpath= Filenames.get (4); } TextView Show=(TextView) Findviewbyid (r.id.show); //Show.settext (imgpath);        /* * the TAG currently defined by the Android SDK is: public static final String tag_orientation = "Orientatio n "; Direction public static final String tag_datetime = "DATETIME"; Time Date public static final String Tag_make = "make"; Device manufacturer public static final String Tag_model = "MODEL"; Device model public static final String Tag_flash = "FLASH"; Flash public static final String tag_image_width = "ImageWidth"; Picture wide public static final String tag_image_length = "Imagelength"; Picture long public static final String tag_gps_latitude = "Gpslatitude"; Latitude public static final String tag_gps_longitude = "Gpslongitude"; Longitude public static final String tag_gps_latitude_ref = "Gpslatituderef"; Latitude reference public static final String tag_gps_longitude_ref = "Gpslongituderef"; Longitude reference public static final String tag_exposure_time = "Exposuretime"; Exposure time public static final String tag_aperture = "Fnumber";    Aperture value public static final String Tag_iso = "Isospeedratings"; */     Try {      //Android Read pictures exif informationExifinterface exifinterface=NewExifinterface (Imgpath); String Orientation=Exifinterface.getattribute (exifinterface.tag_orientation); String DateTime=Exifinterface.getattribute (exifinterface.tag_datetime); String Make=Exifinterface.getattribute (Exifinterface.tag_make); String Model=Exifinterface.getattribute (Exifinterface.tag_model); String Flash=Exifinterface.getattribute (Exifinterface.tag_flash); String ImageWidth=Exifinterface.getattribute (exifinterface.tag_image_width); String Imagelength=Exifinterface.getattribute (exifinterface.tag_image_length); String Exposuretime=Exifinterface.getattribute (exifinterface.tag_exposure_time); String Fnumber=Exifinterface.getattribute (exifinterface.tag_aperture); String isospeedratings=Exifinterface.getattribute (Exifinterface.tag_iso); Text.append ("Path---" + imgpath + "\ n"); Text.append ("Direction---" + Orientation + "\ n"); Text.append ("Time Date---" + DateTime + "\ n"); Text.append ("Device manufacturer---" + make + "\ n"); Text.append ("Device Model---" + model + "\ n"); Text.append ("Flash---" + flash + "\ n"); Text.append ("Picture Width---" + imagewidth + "\ n"); Text.append ("Picture Long---" + imagelength + "\ n"); Text.append ("Exposure Time---" + exposuretime + "\ n"); Text.append ("Aperture value---" + fnumber + "\ n"); Text.append ("Isospeedratings---" + isospeedratings + "\ n"); Exifinterface.setattribute ("MyTag", "Test"); Text.append ("MyTag---" + exifinterface.getattribute ("MyTag") + "\ n"); } Catch(Exception e) {e.printstacktrace ();      } show.settext (text); }  }

Note To add permissions
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>

Code See Https://github.com/huanyi0723/ExifDemo

Android Pictures EXIF information related to get and modify

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.