Skip to content

Commit 9d134fc

Browse files
committed
Fix heic rotate
1 parent 8da417a commit 9d134fc

6 files changed

Lines changed: 51 additions & 53 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Step 2.Add the dependency
1919

2020
```css
2121
dependencies {
22-
implementation 'com.github.forJrking:KLuban:1.0.7'
22+
implementation 'com.github.forJrking:KLuban:1.1.0'
2323
}
2424
```
2525

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ 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-6.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip

library/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ dependencies {
4545
// liveData
4646
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
4747
//图片解码
48-
// implementation 'androidx.exifinterface:exifinterface:1.3.0'
48+
implementation 'androidx.exifinterface:exifinterface:1.3.2'
4949
//进程级别
5050
implementation 'androidx.lifecycle:lifecycle-process:2.2.0'
51-
implementation "androidx.exifinterface:exifinterface:1.3.2"
5251
implementation 'androidx.fragment:fragment-ktx:1.2.5'
5352
compileOnly ("com.github.bumptech.glide:glide:4.11.0@aar")
5453

library/src/main/java/com/forjrking/lubankt/Checker.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
package com.forjrking.lubankt
22

3+
import android.annotation.SuppressLint
34
import android.app.Application
45
import android.content.Context
5-
import android.media.ExifInterface
6+
import android.os.Build
67
import android.util.DisplayMetrics
78
import android.util.Log
89
import android.view.WindowManager
10+
import androidx.exifinterface.media.ExifInterface
911
import com.forjrking.lubankt.io.BufferedInputStreamWrap
1012
import com.forjrking.lubankt.parser.DefaultImgHeaderParser
11-
import com.forjrking.lubankt.parser.ExifInterfaceImageHeaderParser
13+
import com.forjrking.lubankt.parser.ExifInterfaceImgHeaderParser
1214
import com.forjrking.lubankt.parser.ImageType
1315
import com.forjrking.lubankt.parser.ImgHeaderParser
1416
import java.io.File
1517
import java.io.IOException
1618
import java.io.InputStream
1719
import kotlin.jvm.Throws
18-
20+
/**
21+
* @Des: 工具类的方法 内部持有Context通过反射获取的ApplicationContext
22+
* @Author: forjrking
23+
* @Time: 2021/6/18 6:23 下午
24+
* @Version: 1.0.0
25+
**/
26+
@SuppressLint("StaticFieldLeak")
1927
internal object Checker {
2028

2129
// Right now we're only using this parser for HEIF images, which are only supported on OMR1+.
@@ -24,12 +32,14 @@ internal object Checker {
2432
mutableListOf<ImgHeaderParser>().apply {
2533
add(DefaultImgHeaderParser())
2634
//可以自定义新的解码器
27-
add(ExifInterfaceImageHeaderParser())
35+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
36+
//支持HEIF
37+
add(ExifInterfaceImgHeaderParser())
38+
}
2839
}
2940
}
3041

3142
const val TAG = "Luban"
32-
3343
//常用压缩比
3444
private const val DEFAULT_QUALITY = 66
3545
private const val DEFAULT_LOW_QUALITY = 60

library/src/main/java/com/forjrking/lubankt/parser/ExifInterfaceImageHeaderParser.java

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.forjrking.lubankt.parser
2+
3+
import androidx.exifinterface.media.ExifInterface
4+
import java.io.IOException
5+
import java.io.InputStream
6+
7+
/**
8+
* Uses [ExifInterface] to parse orientation data.
9+
*
10+
* ExifInterface supports the HEIF format on OMR1+. Glide's [DefaultImgHeaderParser]
11+
* doesn't currently support HEIF. In the future we should reconcile these two classes, but for now
12+
* this is a simple way to ensure that HEIF files are oriented correctly on platforms where they're
13+
* supported.
14+
*/
15+
internal class ExifInterfaceImgHeaderParser : ImgHeaderParser {
16+
17+
override fun getType(input: InputStream): ImageType {
18+
return ImageType.UNKNOWN
19+
}
20+
21+
@Throws(IOException::class)
22+
override fun getOrientation(input: InputStream): Int {
23+
val result = try {
24+
ExifInterface(input)
25+
.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
26+
} catch (e: Throwable) {
27+
ImgHeaderParser.UNKNOWN_ORIENTATION
28+
}
29+
return if (result == ExifInterface.ORIENTATION_UNDEFINED) {
30+
ImgHeaderParser.UNKNOWN_ORIENTATION
31+
} else result
32+
}
33+
}

0 commit comments

Comments
 (0)