Skip to content

Commit 72fb132

Browse files
committed
force use RGB565 decode bitmap.
1 parent 1c5b199 commit 72fb132

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

library/src/main/java/com/opensource/svgaplayer/SVGAVideoEntity.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import org.json.JSONObject
77
import java.io.File
88
import java.util.*
99

10+
private val options = BitmapFactory.Options()
11+
1012
/**
1113
* Created by PonyCui_Home on 16/6/18.
1214
*/
@@ -58,14 +60,15 @@ class SVGAVideoEntity {
5860
private fun resetImages(obj: JSONObject) {
5961
obj.optJSONObject("images")?.let { imgObjects ->
6062
imgObjects.keys().forEach { imageKey ->
63+
options.inPreferredConfig = Bitmap.Config.RGB_565
6164
var filePath = cacheDir.absolutePath + "/" + imgObjects[imageKey]
62-
var bitmap = if (File(filePath).exists()) BitmapFactory.decodeFile(filePath) else null
65+
var bitmap = if (File(filePath).exists()) BitmapFactory.decodeFile(filePath, options) else null
6366
if (bitmap != null) {
6467
images.put(imageKey, bitmap)
6568
}
6669
else {
6770
(cacheDir.absolutePath + "/" + imageKey + ".png")?.takeIf { File(it).exists() }?.let { it
68-
BitmapFactory.decodeFile(it)?.let {
71+
BitmapFactory.decodeFile(it, options)?.let {
6972
images.put(imageKey, it)
7073
}
7174
}
@@ -77,20 +80,21 @@ class SVGAVideoEntity {
7780
private fun resetImages(obj: MovieEntity) {
7881
obj.images?.entries?.forEach {
7982
val imageKey = it.key
80-
val bitmap = BitmapFactory.decodeByteArray(it.value.toByteArray(), 0, it.value.size())
83+
options.inPreferredConfig = Bitmap.Config.RGB_565
84+
val bitmap = BitmapFactory.decodeByteArray(it.value.toByteArray(), 0, it.value.size(), options)
8185
if (bitmap != null) {
8286
images.put(imageKey, bitmap)
8387
}
8488
else {
8589
it.value.utf8()?.let {
8690
var filePath = cacheDir.absolutePath + "/" + it
87-
var bitmap = if (File(filePath).exists()) BitmapFactory.decodeFile(filePath) else null
91+
var bitmap = if (File(filePath).exists()) BitmapFactory.decodeFile(filePath, options) else null
8892
if (bitmap != null) {
8993
images.put(imageKey, bitmap)
9094
}
9195
else {
9296
(cacheDir.absolutePath + "/" + imageKey + ".png")?.takeIf { File(it).exists() }?.let { it
93-
BitmapFactory.decodeFile(it)?.let {
97+
BitmapFactory.decodeFile(it, options)?.let {
9498
images.put(imageKey, it)
9599
}
96100
}

0 commit comments

Comments
 (0)