|
1 /* |
|
2 * Copyright (C) 2013 Square, Inc. |
|
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 package com.squareup.picasso; |
|
17 |
|
18 import android.content.Context; |
|
19 import android.graphics.Bitmap; |
|
20 import android.media.ExifInterface; |
|
21 import android.net.Uri; |
|
22 import java.io.IOException; |
|
23 |
|
24 import static android.media.ExifInterface.ORIENTATION_NORMAL; |
|
25 import static android.media.ExifInterface.ORIENTATION_ROTATE_180; |
|
26 import static android.media.ExifInterface.ORIENTATION_ROTATE_270; |
|
27 import static android.media.ExifInterface.ORIENTATION_ROTATE_90; |
|
28 import static android.media.ExifInterface.TAG_ORIENTATION; |
|
29 |
|
30 class FileBitmapHunter extends ContentStreamBitmapHunter { |
|
31 |
|
32 FileBitmapHunter(Context context, Picasso picasso, Dispatcher dispatcher, Cache cache, |
|
33 Stats stats, Action action) { |
|
34 super(context, picasso, dispatcher, cache, stats, action); |
|
35 } |
|
36 |
|
37 @Override Bitmap decode(Request data) |
|
38 throws IOException { |
|
39 setExifRotation(getFileExifRotation(data.uri)); |
|
40 return super.decode(data); |
|
41 } |
|
42 |
|
43 static int getFileExifRotation(Uri uri) throws IOException { |
|
44 ExifInterface exifInterface = new ExifInterface(uri.getPath()); |
|
45 int orientation = exifInterface.getAttributeInt(TAG_ORIENTATION, ORIENTATION_NORMAL); |
|
46 switch (orientation) { |
|
47 case ORIENTATION_ROTATE_90: |
|
48 return 90; |
|
49 case ORIENTATION_ROTATE_180: |
|
50 return 180; |
|
51 case ORIENTATION_ROTATE_270: |
|
52 return 270; |
|
53 default: |
|
54 return 0; |
|
55 } |
|
56 } |
|
57 } |