1 /* 2 * Copyright (C) 2011 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.gallery3d.data; 18 19 import android.util.Log; 20 21 import com.android.gallery3d.exif.ExifInterface; 22 23 import java.io.IOException; 24 import java.io.InputStream; 25 26 public class Exif { 27 private static final String TAG = "CameraExif"; 28 29 // Returns the degrees in clockwise. Values are 0, 90, 180, or 270. 30 public static int getOrientation(InputStream is) { 31 if (is == null) { 32 return 0; 33 } 34 ExifInterface exif = new ExifInterface(); 35 try { 36 exif.readExif(is); 37 Integer val = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION); 38 if (val == null) { 39 return 0; 40 } else { 41 return ExifInterface.getRotationForOrientationValue(val.shortValue()); 42 } 43 } catch (IOException e) { 44 Log.w(TAG, "Failed to read EXIF orientation", e); 45 return 0; 46 } 47 } 48 } 49