michael@0: /* michael@0: * Copyright (C) 2013 Square, Inc. michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: package com.squareup.picasso; michael@0: michael@0: import android.content.Context; michael@0: import android.graphics.Bitmap; michael@0: import android.media.ExifInterface; michael@0: import android.net.Uri; michael@0: import java.io.IOException; michael@0: michael@0: import static android.media.ExifInterface.ORIENTATION_NORMAL; michael@0: import static android.media.ExifInterface.ORIENTATION_ROTATE_180; michael@0: import static android.media.ExifInterface.ORIENTATION_ROTATE_270; michael@0: import static android.media.ExifInterface.ORIENTATION_ROTATE_90; michael@0: import static android.media.ExifInterface.TAG_ORIENTATION; michael@0: michael@0: class FileBitmapHunter extends ContentStreamBitmapHunter { michael@0: michael@0: FileBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache, michael@0: Stats stats, Action action) { michael@0: super(context, picasso, dispatcher, cache, stats, action); michael@0: } michael@0: michael@0: @Override Bitmap decode(Request data) michael@0: throws IOException { michael@0: setExifRotation(getFileExifRotation(data.uri)); michael@0: return super.decode(data); michael@0: } michael@0: michael@0: static int getFileExifRotation(Uri uri) throws IOException { michael@0: ExifInterface exifInterface = new ExifInterface(uri.getPath()); michael@0: int orientation = exifInterface.getAttributeInt(TAG_ORIENTATION, ORIENTATION_NORMAL); michael@0: switch (orientation) { michael@0: case ORIENTATION_ROTATE_90: michael@0: return 90; michael@0: case ORIENTATION_ROTATE_180: michael@0: return 180; michael@0: case ORIENTATION_ROTATE_270: michael@0: return 270; michael@0: default: michael@0: return 0; michael@0: } michael@0: } michael@0: }