mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package io.legado.app.model.localBook
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.text.TextUtils
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
@@ -85,11 +84,13 @@ class EpubFile(var book: Book) {
|
||||
if (!File(book.coverUrl!!).exists()) {
|
||||
/*部分书籍DRM处理后,封面获取异常,待优化*/
|
||||
it.coverImage?.inputStream?.use { input ->
|
||||
val cover = BitmapFactory.decodeStream(input)
|
||||
val out = FileOutputStream(FileUtils.createFileIfNotExist(book.coverUrl!!))
|
||||
cover.compress(Bitmap.CompressFormat.JPEG, 90, out)
|
||||
out.flush()
|
||||
out.close()
|
||||
BitmapUtils.decodeBitmap(input)?.let { cover ->
|
||||
val out =
|
||||
FileOutputStream(FileUtils.createFileIfNotExist(book.coverUrl!!))
|
||||
cover.compress(Bitmap.CompressFormat.JPEG, 90, out)
|
||||
out.flush()
|
||||
out.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.graphics.Color
|
||||
import com.google.android.renderscript.Toolkit
|
||||
import java.io.FileInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import kotlin.math.*
|
||||
|
||||
|
||||
@@ -81,6 +82,23 @@ object BitmapUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/** 从path中获取Bitmap图片
|
||||
* @param path 图片路径
|
||||
* @return
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun decodeBitmap(inputStream: InputStream): Bitmap? {
|
||||
return inputStream.use {
|
||||
val opts = BitmapFactory.Options()
|
||||
opts.inJustDecodeBounds = true
|
||||
|
||||
BitmapFactory.decodeStream(inputStream, null, opts)
|
||||
opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128)
|
||||
opts.inJustDecodeBounds = false
|
||||
BitmapFactory.decodeStream(inputStream, null, opts)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以最省内存的方式读取本地资源的图片
|
||||
* @param context 设备上下文
|
||||
|
||||
Reference in New Issue
Block a user