• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.camera;
18 
19 import android.util.Log;
20 
21 import com.android.camera.exif.ExifInterface;
22 
23 import java.io.IOException;
24 
25 public class Exif {
26     private static final String TAG = "CameraExif";
27 
getExif(byte[] jpegData)28     public static ExifInterface getExif(byte[] jpegData) {
29         ExifInterface exif = new ExifInterface();
30         try {
31             exif.readExif(jpegData);
32         } catch (IOException e) {
33             Log.w(TAG, "Failed to read EXIF data", e);
34         }
35         return exif;
36     }
37 
38     // Returns the degrees in clockwise. Values are 0, 90, 180, or 270.
getOrientation(ExifInterface exif)39     public static int getOrientation(ExifInterface exif) {
40         Integer val = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
41         if (val == null) {
42             return 0;
43         } else {
44             return ExifInterface.getRotationForOrientationValue(val.shortValue());
45         }
46     }
47 
getOrientation(byte[] jpegData)48     public static int getOrientation(byte[] jpegData) {
49         if (jpegData == null) return 0;
50 
51         ExifInterface exif = getExif(jpegData);
52         return getOrientation(exif);
53     }
54 }
55