aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/utils/ImageUtils.java
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-01-12 13:30:34 +0100
committerBananeweizen <bananeweizen@gmx.de>2014-01-12 13:30:34 +0100
commit05ccbe7f00e3ab378cc83fc7aed1a62f7aae6ad6 (patch)
treeea1d548ba5814c1c803b0723583416875092fda7 /main/src/cgeo/geocaching/utils/ImageUtils.java
parentd6acd75d48e3be99c3b96eda9eb89971289d09b3 (diff)
parenta74eba6f08bb6dc718c25b6e25177aaafb3fc47d (diff)
downloadcgeo-05ccbe7f00e3ab378cc83fc7aed1a62f7aae6ad6.zip
cgeo-05ccbe7f00e3ab378cc83fc7aed1a62f7aae6ad6.tar.gz
cgeo-05ccbe7f00e3ab378cc83fc7aed1a62f7aae6ad6.tar.bz2
Merge remote-tracking branch 'origin/release'
Diffstat (limited to 'main/src/cgeo/geocaching/utils/ImageUtils.java')
-rw-r--r--main/src/cgeo/geocaching/utils/ImageUtils.java31
1 files changed, 27 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/utils/ImageUtils.java b/main/src/cgeo/geocaching/utils/ImageUtils.java
index fad1e0d..9f47ead 100644
--- a/main/src/cgeo/geocaching/utils/ImageUtils.java
+++ b/main/src/cgeo/geocaching/utils/ImageUtils.java
@@ -8,9 +8,11 @@ import org.eclipse.jdt.annotation.Nullable;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
+import android.media.ExifInterface;
import android.net.Uri;
import java.io.BufferedOutputStream;
@@ -22,6 +24,13 @@ import java.util.Date;
import java.util.Locale;
public final class ImageUtils {
+ private static final int[] ORIENTATIONS = new int[] {
+ ExifInterface.ORIENTATION_ROTATE_90,
+ ExifInterface.ORIENTATION_ROTATE_180,
+ ExifInterface.ORIENTATION_ROTATE_270
+ };
+
+ private static final int[] ROTATION = new int[] { 90, 180, 270 };
private ImageUtils() {
// Do not let this class be instantiated, this is a utility class.
@@ -153,18 +162,32 @@ public final class ImageUtils {
*/
@Nullable
public static Bitmap readDownsampledImage(@NonNull final String filePath, final int maxX, final int maxY) {
- BitmapFactory.Options sizeOnlyOptions = new BitmapFactory.Options();
+ int orientation = ExifInterface.ORIENTATION_NORMAL;
+ try {
+ final ExifInterface exif = new ExifInterface(filePath);
+ orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
+ } catch (IOException e) {
+ Log.e("ImageUtils.readDownsampledImage", e);
+ }
+ final BitmapFactory.Options sizeOnlyOptions = new BitmapFactory.Options();
sizeOnlyOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, sizeOnlyOptions);
final int myMaxXY = Math.max(sizeOnlyOptions.outHeight, sizeOnlyOptions.outWidth);
final int maxXY = Math.max(maxX, maxY);
final int sampleSize = myMaxXY / maxXY;
+ final BitmapFactory.Options sampleOptions = new BitmapFactory.Options();
if (sampleSize > 1) {
- BitmapFactory.Options sampleOptions = new BitmapFactory.Options();
sampleOptions.inSampleSize = sampleSize;
- return BitmapFactory.decodeFile(filePath, sampleOptions);
}
- return BitmapFactory.decodeFile(filePath);
+ final Bitmap decodedImage = BitmapFactory.decodeFile(filePath, sampleOptions);
+ for (int i = 0; i < ORIENTATIONS.length; i++) {
+ if (orientation == ORIENTATIONS[i]) {
+ final Matrix matrix = new Matrix();
+ matrix.postRotate(ROTATION[i]);
+ return Bitmap.createBitmap(decodedImage, 0, 0, decodedImage.getWidth(), decodedImage.getHeight(), matrix, true);
+ }
+ }
+ return decodedImage;
}
/** Create a File for saving an image or video