Skip to content

Commit 1c41817

Browse files
author
Marius Merkevicius
committed
Add exif support
Applying patch from unfinished MR Source: hkk595#8
1 parent e502c71 commit 1c41817

File tree

39 files changed

+454
-12
lines changed

39 files changed

+454
-12
lines changed

build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4+
ext.kotlin_version = '1.2.51'
5+
46
repositories {
57
google()
68
jcenter()
9+
maven { url 'https://maven.google.com' }
10+
maven { url "https://jitpack.io" }
711
}
812
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.1'
13+
classpath 'com.android.tools.build:gradle:3.1.3'
1014
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1115

1216
// NOTE: Do not place your application dependencies here; they belong
1317
// in the individual module build.gradle files
18+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1419
}
1520
}
1621

1722
allprojects {
1823
repositories {
1924
google()
2025
jcenter()
26+
maven { url 'https://maven.google.com' }
27+
maven { url "https://jitpack.io" }
2128
}
2229
}
2330

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Nov 21 01:40:52 HKT 2017
1+
#Tue Jul 10 18:02:03 AST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
File renamed without changes.
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33

4-
group='com.github.hkk595'
4+
group = 'com.github.hkk595'
55

66
android {
7-
compileSdkVersion 26
7+
compileSdkVersion 27
88
defaultConfig {
99
minSdkVersion 16
10-
targetSdkVersion 26
10+
targetSdkVersion 27
1111
versionCode 1
1212
versionName "1.0"
1313
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -22,10 +22,15 @@ android {
2222

2323
dependencies {
2424
implementation fileTree(dir: 'libs', include: ['*.jar'])
25-
implementation 'com.android.support:appcompat-v7:26.1.0'
25+
implementation 'com.android.support:appcompat-v7:27.1.1'
2626
testImplementation 'junit:junit:4.12'
2727
androidTestImplementation 'com.android.support.test:runner:1.0.1'
2828
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
29+
implementation "com.github.jkwiecien:EasyImage:2.0.4"
2930

30-
compile 'io.reactivex.rxjava2:rxjava:2.1.6'
31+
implementation 'io.reactivex.rxjava2:rxjava:2.1.6'
32+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
3133
}
34+
35+
apply plugin: 'kotlin-android'
36+
apply plugin: 'kotlin-android-extensions'

app/src/androidTest/java/me/echodev/resizer/ExampleInstrumentedTest.java renamed to library/src/androidTest/java/me/echodev/resizer/ExampleInstrumentedTest.java

File renamed without changes.
File renamed without changes.

app/src/main/java/me/echodev/resizer/util/FileUtils.java renamed to library/src/main/java/me/echodev/resizer/util/FileUtils.java

File renamed without changes.

app/src/main/java/me/echodev/resizer/util/ImageUtils.java renamed to library/src/main/java/me/echodev/resizer/util/ImageUtils.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.graphics.Bitmap;
44
import android.graphics.BitmapFactory;
5+
import android.graphics.Matrix;
6+
import android.media.ExifInterface;
57

68
import java.io.File;
79
import java.io.IOException;
@@ -12,7 +14,7 @@
1214

1315
public class ImageUtils {
1416
public static File getScaledImage(int targetLength, int quality, Bitmap.CompressFormat compressFormat,
15-
String outputDirPath, String outputFilename, File sourceImage) throws IOException {
17+
String outputDirPath, String outputFilename, File sourceImage) throws IOException {
1618
File directory = new File(outputDirPath);
1719
if (!directory.exists()) {
1820
directory.mkdirs();
@@ -28,7 +30,7 @@ public static File getScaledImage(int targetLength, int quality, Bitmap.Compress
2830
return new File(outputFilePath);
2931
}
3032

31-
public static Bitmap getScaledBitmap(int targetLength, File sourceImage) {
33+
public static Bitmap getScaledBitmap(int targetLength, File sourceImage) throws IOException {
3234
BitmapFactory.Options options = new BitmapFactory.Options();
3335
options.inJustDecodeBounds = false;
3436
Bitmap bitmap = BitmapFactory.decodeFile(sourceImage.getAbsolutePath(), options);
@@ -50,6 +52,20 @@ public static Bitmap getScaledBitmap(int targetLength, File sourceImage) {
5052
targetWidth = Math.round(targetHeight / aspectRatio);
5153
}
5254

53-
return Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, true);
55+
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, true);
56+
57+
//check the rotation of the image and display it properly
58+
ExifInterface exif;
59+
exif = new ExifInterface(sourceImage.getAbsolutePath());
60+
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
61+
Matrix matrix = new Matrix();
62+
if (orientation == 6) {
63+
matrix.postRotate(90);
64+
} else if (orientation == 3) {
65+
matrix.postRotate(180);
66+
} else if (orientation == 8) {
67+
matrix.postRotate(270);
68+
}
69+
return Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true);
5470
}
5571
}

0 commit comments

Comments
 (0)