What is EXIF under Android _android

Source: Internet
Author: User
Tags color gamut

A. What is EXIF
Exif (exchangeable image file) is an image file format that has exactly the same data storage as the JPEG format. In fact, the EXIF format is a digital photo inserted in the header of the JPEG format. Including the aperture, shutter, white balance, ISO, focal length, date and time, and other shooting conditions as well as camera brand, model, color coding, recording sound and the Global Positioning System (GPS), thumbnails and so on. Simply put, the exif=jpeg+ takes a shot of parameters. As a result, you can view images in EXIF format with any viewing software that can look at 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". There is a series of "0xFF??" in the header of the file. A string of formats, called "identities," used to mark the information segment of a JPEG file. "0xffd8" indicates the beginning of the image information, "0xffd9" means the end of the image information, the two identities are not followed by information, and the other identities are followed by some information characters.
0XFFE0--The identifiers between 0xFFEF are called "Application tags" and are not used by regular JPEG files, and EXIF uses these information strings to record information such as shutter speed, aperture value, and even global positioning information. According to the Exif2.1 standard definition of these identifiers, the digital camera can be recorded in a variety of shooting information in digital images, the application software can read the data, and then according to the Exif2.1 standard, to retrieve their specific meaning, in general, including the following information:
Image Description images description, source. Refers to the tool that generates images
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 in the direction of some camera support, some do not support
Xresolution/yresolution x/y Directional Resolution This column already has a specific entry to explain this problem.
Resolutionunit resolution units are generally PPI
Software software displays firmware firmware version
DateTime Date and Time
ycbcrpositioning hue Positioning
EXIFOFFSETEXIF information location, definition of EXIF in the information written in the file, some software does not show.
Exposuretime exposure time is the shutter speed
Fnumber aperture coefficient
Exposureprogram Exposure program refers to the setup of automatic exposure, the different cameras, may be Sutter Priority (shutter priority), Aperture Priority (shutter priority) and so on.
ISO speed Ratings sensitivity
Exifversionexif version
Datetimeoriginal creation Time
Datetimedigitized Digital Time
Componentsconfiguration Image Construction (multi-fingered color combination scheme)
Compressedbitsperpixel (BPP) compression per pixel color bit compression degree
Exposurebiasvalue exposure compensation.
Maxaperturevalue Max Aperture
Meteringmode metering method, average metering, central focus metering, point metering and so on.
LightSource light source refers to the white balance setting
Whether Flash uses Flash.
Focallength focal length, the general display lens physical focal length, some software may define a factor, thus displays corresponds to the 35mm camera focal length Makernote (User Comment) Author marking, the description, the record
Flashpixversionflashpix version (supported by individual models)
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 generic extension definition pointers and TIFF files related to the specific meaning of the unknown
Filesource source file compression compression ratio.

Two. Camera Photography process

In the Android Camera program development process, the use of EXIF-related knowledge, if handled improperly, will result in the shooting of JPEG images can not be normal browsing.
In the Froyo (Android 2.2) Source of the camera application is not to the EXIF information to write operations, but only read operations, for EXIF writes to the camera hardware abstraction layer to complete, this is Google's design logic. But the different Android platform and its related platform, together with different camera applications, alternating, arrange the combination, there may be such a situation: the bottom is not to write Exif, and the upper application did not write EXIF information, then the picture display information will be lost. The most serious of these is the orientation parameter.

The logic of Froyo camera is this:
In camera this activity, there is an internal 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 direction of the camera to the camera.parameters example;
2. Transmit all camera parameters to the Android.hardware.Camera object;
3. Call method Takepicture, and set up very important 4 callback;
4. The things that generate EXIF data are done by HAL;
5. The 4th callback return data (this callback is the most important and is not default, that is, the first 3 callback set to NULL does 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 as JPEG data, is a variety of parameters (i.e. Camera.parameters instances) transmitted by the HAL layer according to the application and the JPEG compression algorithm is generated.
mimagecapture.storeimage (jpegdata, Camera, mlocation);
}

Three. Exif use method and code optimization plan

Where is the EXIF information used? I met at least a few places like the following:
1. Generate the upper-right corner of the sketch;
2. Picture display applications, such as Android Gallery3d applications;
3. Picture echo;
4. Short (color) letter, etc. need to add camera attachment application.

Look at the source code: Imagemanager In this way to read EXIF direction parameters.

 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 write for Exif information is no longer dependent on the underlying. That is to compare the transmission to the bottom of the orientation and the actual return is equal, is not equal to the underlying write EXIF information error, we can be modified in the application layer.
You can add a Judgment branch as follows: (where exif_orientation is the value that our cached application passes to the bottom).

else if (orientation = = 0 && exif_orientation!= 0) {
        switch (exif_orientation) {case
        :
          orientation = exifinterface.orientation_rotate_90;
          degree = N;
          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 operations for EXIF at the application level are accomplished through the Android.media.ExifInterface interface.
is set by public void setattribute (string tag, string value), which can be obtained by public int getattributeint (string tag, int defaultvalue and public string getattribute (string tag), getattributeint the default value set by the second parameter of the overloaded method, and returns the value of the corresponding tag if successful; The specific integer content returns the value directly for the method. And overloaded method Two this method returns the result directly, or null if it fails.

The above is the entire content of this article, I hope to help you learn.

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.