Android and androidsdk

Source: Internet
Author: User

Android and androidsdk
Exif

Exif is an image file format, and its data is stored in the same JPEG format. In fact, Exif is a JPEG format header that inserts digital photo information, including the aperture, shutter, balance white, ISO, focal length, date and time, and other shooting conditions, as well as the camera brand, model, color encoding, and GPS.

ExifInterface

In Android, The ExifInterface class is used to operate the Exif information of an image. Although the class name contains an Interface, it is not an Interface. It is a class and is in the "android. media. exifInterface is a part of the library's function implementation. ExifInterface has a constructor that accepts data of the String type. This is the address for reading image files.

Exif data can be stored as a Key-value pair in the image. The following operations are generally performed:

String getAttribute (String tag) // obtain the String value of the tag attribute in the image. Double getAttribute (String tag, double defaultValue) // obtain the double value of the tag attribute in the image. Int getAttributeInt (String tag, defaultValue // gets the int value of the tag attribute in the image. Void setAttribute (String tag, String value) // set the image Exif value based on input parameters. Void saveAttrubutes () // write the Exif of the image in the memory to the image.

As you can see, most of the methods above operate on a String type tag parameter, which is the attribute of Exif. Some static constants of strings are defined in ExifInterface to represent these tag values, which are commonly used as follows:

TAG_APERTURE // the aperture value. TAG_DATETIME // The shooting time, depending on the time set by the device. TAG_EXPOSURE_TIME // specifies the exposure time. TAG_FLASH // flashlight. TAG_FOCAL_LENGTH // focal length. TAG_IMAGE_LENGTH // The Image Height. TAG_IMAGE_WIDTH // The image width. TAG_ISO // ISO. TAG_MAKE // device brand. TAG_MODEL // device model, which is expressed by an integer and has a constant in the ExifInterface. TAG_ORIENTATION // rotation angle, which is expressed by an integer. There is a constant in the ExifInterface.
Obtain Exif
ExifInterface exifInterface = new ExifInterface("/sdcard/a.jpg");String FFNumber = exifInterface.getAttribute(ExifInterface.TAG_APERTURE);String FDateTime = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);String FExposureTime = exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);String FFlash = exifInterface.getAttribute(ExifInterface.TAG_FLASH);String FFocalLength = exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);String FImageLength = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);String FImageWidth = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);String FISOSpeedRatings = exifInterface.getAttribute(ExifInterface.TAG_ISO);String FMake = exifInterface.getAttribute(ExifInterface.TAG_MAKE);String FModel = exifInterface.getAttribute(ExifInterface.TAG_MODEL);String FOrientation = exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);String FWhiteBalance = exifInterface.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
Write Exif

Exif information is stored in binary format in the image. The number of data digits stored in each field is fixed, and the number of tags is also fixed, therefore, we can only operate on the existing tag value in the image Exif information, and save the data according to its storage space limit. If the storage data type is incorrect, the stored data may not be correctly retrieved, and the excess digits will be intercepted. If you cannot store the data of a string in TAG_ORIENTATION, it must store the int type value and the extra values will be truncated.

// TagString strAttr = ExifInterface. TAG_ORIENTATION; // tag-valueString strValue = et_value.getText (). toString (). trim (); // obtain the image ExifExifInterface exif = new ExifInterface ("/sdcard/a.jpg"); // Save the value of the specified tag exif. setAttribute (strAttr, strValue); // write the Exif information to the target image exif. saveAttributes ();
I am the dividing line of tiantiao

Related Article

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.