pull/2237/head
Xwite 2 years ago
parent fe2271f357
commit b29ce638df
  1. 7
      app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
  2. 18
      app/src/main/java/io/legado/app/utils/BitmapUtils.kt

@ -1,6 +1,7 @@
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
@ -84,16 +85,14 @@ class EpubFile(var book: Book) {
if (!File(book.coverUrl!!).exists()) {
/*部分书籍DRM处理后,封面获取异常,待优化*/
it.coverImage?.inputStream?.use { input ->
BitmapUtils.decodeBitmap(input)?.let { cover ->
val out =
FileOutputStream(FileUtils.createFileIfNotExist(book.coverUrl!!))
val cover = BitmapFactory.decodeStream(input)
val out = FileOutputStream(FileUtils.createFileIfNotExist(book.coverUrl!!))
cover.compress(Bitmap.CompressFormat.JPEG, 90, out)
out.flush()
out.close()
}
}
}
}
} catch (e: Exception) {
e.printOnDebug()
}

@ -10,7 +10,6 @@ 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.*
@ -82,23 +81,6 @@ 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 设备上下文

Loading…
Cancel
Save