The EXIF under Android

Source: Internet
Author: User
Tags color gamut

I. What is EXIF

Exif (exchangeable image file) is a image file format whose data storage is identical to the JPEG format. In fact, the EXIF format is the insertion of digital photos in the head of the JPEG format, including aperture, shutter, white balance, ISO, focal length, date and time, and shooting conditions as well as camera brand, model, color coding, recorded sound during shooting and global Positioning System (GPS), thumbnails, etc. To put it simply, exif=jpeg+ the shooting parameters. As a result, you can browse the EXIF format with any viewing software that can view JPEG files, but not all graphics programs can handle EXIF information.

All JPEG files begin with the string "0xffd8" and End With the string "0xffd9". The file header has a series of "0xFF??" A formatted string, called an "identity," that is used to mark the information segment of a JPEG file. "0xffd8" means that the image information begins, "0xffd9" means the end of the image information, there is no information behind the two identities, and the other identifiers follow some information characters.
0XFFE0-The identifier between 0xFFEF is called "Application Tag" and is not used by regular JPEG files, so EXIF uses these information strings to record the shooting information such as shutter speed, aperture value, etc., and even can include global positioning information. According to the definition of these identifiers in accordance with the Exif2.1 standard, digital cameras can record various shooting information into digital images, the application software can read the data, and then according to the Exif2.1 standard, retrieve their specific meaning, generally include the following information:
Image Description Description, source. Refers to the tool that generates the image
Artist author Some cameras can enter the user's name
Make producer refers to the product manufacturer
Model model refers to the type of equipment
Orientation direction some camera support, and some do not support
Xresolution/yresolution x/Y direction Resolution This column already has a special entry explaining this issue.
Resolutionunit resolution units are typically PPI
Software software display firmware firmware version
DateTime Date and Time
ycbcrpositioning hue Positioning
Exifoffsetexif information location, defines EXIF write in the file, some software does not display.
Exposuretime exposure time is the shutter speed
Fnumber aperture coefficient
Exposureprogram Exposure program refers to the setting of program AE, each camera is different, may be Sutter priority (shutter first), Aperture priority (shutter first) and so on.
ISO Speed Ratings Sensitivity
Exifversionexif version
Datetimeoriginal creation Time
Datetimedigitized Digital Time
Componentsconfiguration Image Construction (multi-finger color combination scheme)
Compressedbitsperpixel (BPP) compression per pixel color position refers to the degree of compression
Exposurebiasvalue exposure compensation.
Maxaperturevalue Maximum aperture
Meteringmode metering method, average metering, center-weighted metering, spot metering, etc.
LightSource light source refers to the white balance setting
Whether Flash uses Flash.
Focallength focal length, generally showing the lens physical focal length, some software can define a coefficient, thus showing the equivalent of 35mm camera focal length Makernote (User Comment) author tag, description, record
Flashpixversionflashpix version (individual models supported)
ColorSpace color gamut, color space
Exifimagewidth (Pixel X Dimension) image width refers to the number of transverse pixels
Exifimagelength (Pixel Y Dimension) Image height refers to the number of longitudinal pixels
Interoperability IFD Universal Extension definition pointer and TIFF file related, unspecified meaning
Filesource source file compression compression ratio.

Two. Camera photo process


In the Android Camera program development process, to use EXIF-related knowledge, if not properly handled, will result in the shooting of JPEG images can not be browsed.
In the Froyo (Android 2.2) Source of the camera application is not to write EXIF information, but only read operation, for the EXIF write operation is given to the camera hardware abstraction layer to complete, this is the design logic of Google. But different Android platforms and their associated sub-platforms, coupled with different camera applications, alternating with each other, may appear to be a situation where the bottom line does not write Exif, and the upper application does not write EXIF information, then the image display information will be lost. One of the most serious effects is the orientation parameter.

The logic of the Froyo camera is this:
In the camera activity, there is an inner class imagecapture, which contains an important method:
private void Capture () {
Set rotation.
Mparameters.setrotation (mlastorientation);
....................
.....................
Mcameradevice.setparameters (mparameters);

Mcameradevice.takepicture (Mshuttercallback, Mrawpicturecallback, Mpostviewpicturecallback, new JpegPictureCallback (Loc));
}

The approximate process is this:
1. Add the camera's orientation to the Camera.parameters instance when taking the photo;
2. Pass all camera photo parameters to the Android.hardware.Camera object;
3. Call the method Takepicture, and set up a very important 4 callback;
4. The creation of EXIF data is done by HAL;
5.4th Callback return data (this callback is the most important, and is not the default, that is, the first 3 callback set to NULL will not affect the camera function), see the following code:
Private Final class Jpegpicturecallback implements Picturecallback {
public void Onpicturetaken (final byte[] jpegdata, final Android.hardware.Camera Camera) {
Jpegdata is JPEG data, which is generated by the HAL layer's various parameters (i.e., camera.parameters instances) that are transmitted by the application, as well as the JPEG compression algorithm.
Mimagecapture.storeimage (Jpegdata, Camera, mlocation);
}
}

Three. Exif use method and code optimization scheme


Where to use EXIF information? I met at least a few places like this:
1. Create a sketch in the upper right corner;
2. Image display applications, such as the Gallery3d app with Android's own;
3. Picture echo;
4. Short (color) letters and other applications that need to add camera attachments.

Look at the source: Imagemanager in this way read the exif direction parameter.
public static int getexiforientation (String filepath) {
int degree = 0;
Exifinterface exif = null;
try {
EXIF = new Exifinterface (filepath);
} catch (IOException ex) {
LOG.E (TAG, "cannot read Exif", ex);
}
if (exif! = null) {
int orientation = Exif.getattributeint (
Exifinterface.tag_orientation,-1);
if (Orientation! =-1) {
We only recognize a subset of orientation tag values.
Switch (orientation) {
Case EXIFINTERFACE.ORIENTATION_ROTATE_90:
degree = 90;
Break
Case EXIFINTERFACE.ORIENTATION_ROTATE_180:
degree = 180;
Break
Case EXIFINTERFACE.ORIENTATION_ROTATE_270:
degree = 270;
Break
}

}
}
return degree;
}

This method can be further optimized so that the writing of EXIF information is no longer dependent on the underlying. That is to compare the transfer to the underlying orientation and the actual return is equal, unequal is the underlying write EXIF information error, we can be modified at the application layer.
You can add a decision branch as follows: (where Exif_orientation is our cached app passed to the underlying value).
else if (orientation = = 0 && exif_orientation! = 0) {
Switch (exif_orientation) {
Case 90:
orientation = exifinterface.orientation_rotate_90;
degree = 90;
Break
Case 180:
orientation = exifinterface.orientation_rotate_180;
degree = 180;
Break
Case 270:
orientation = exifinterface.orientation_rotate_270;
degree = 270;
Break
}
Exif.setattribute (Exifinterface.tag_orientation, integer.tostring (ORIENTATION));
try {
Exif.saveattributes ();
} catch (IOException e) {
LOG.E (TAG, "Cannot save Exif", E);
}
}


The operation for EXIF at the application level is done through the Android.media.ExifInterface interface.
Set by public void SetAttribute (string tag, string value), and get can be obtained through public int getattributeint (string tag, int defaultvalue ) and public string getattribute (string tag), Getattributeint overloaded method A second parameter is the default value we set, and if successful, returns the value of the corresponding tag; A specific integer content returns the value directly for the method. Instead of overloading method two, the method returns the result directly, or null if it fails.

Conclusion

Thus, the simple transformation (just added to the EXIF information check and write operation logic) of the camera application will be more robust, do not rely on the platform to handle EXIF information, even if there is an exception, the application can be automatically corrected.
Here is just the orientation parameter in Exif, for example, other parameters can be and so on, to ensure that the picture taken out to meet the standard.

Transferred from: http://blog.csdn.net/zoe6553/article/details/6297409

The EXIF under Android

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.