pull/1787/head
kunfei 2 years ago
parent 8aadfb6848
commit 01125ca6af
  1. 16
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -17,6 +17,8 @@ import io.legado.app.utils.isXml
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import kotlin.math.max
import kotlin.math.min
object ImageProvider { object ImageProvider {
@ -27,10 +29,10 @@ object ImageProvider {
/** /**
*缓存bitmap LruCache实现 *缓存bitmap LruCache实现
*/ */
//private val maxMemory = Runtime.getRuntime().maxMemory() private const val M = 1024 * 1024
//private val cacheMemorySize = (maxMemory / 8) as Int private val cacheSize =
private const val cacheMemorySize: Int = 1024 * 1024 * 1024 //1G max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt()))
private val bitmapLruCache = object : LruCache<String, Bitmap>(cacheMemorySize) { private val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) {
override fun sizeOf(key: String, bitmap: Bitmap): Int { override fun sizeOf(key: String, bitmap: Bitmap): Int {
return bitmap.byteCount return bitmap.byteCount
} }
@ -42,9 +44,9 @@ object ImageProvider {
newBitmap: Bitmap? newBitmap: Bitmap?
) { ) {
if (evicted) { if (evicted) {
oldBitmap.recycle() oldBitmap.recycle()
putDebug("自动回收Bitmap path: $key") putDebug("自动回收Bitmap path: $key")
putDebug("bitmapLruCache : ${size()} / ${maxSize()}") putDebug("bitmapLruCache : ${size()} / ${maxSize()}")
} }
} }
} }

Loading…
Cancel
Save