pull/1397/head
gedoor 4 years ago
parent 502cef4b04
commit fd5c9e0ec4
  1. 6
      app/src/main/java/io/legado/app/model/BookCover.kt
  2. 6
      app/src/main/java/io/legado/app/utils/BitmapUtils.kt

@ -48,9 +48,9 @@ object BookCover {
defaultDrawable = appCtx.resources.getDrawable(R.drawable.image_cover_default, null) defaultDrawable = appCtx.resources.getDrawable(R.drawable.image_cover_default, null)
return return
} }
defaultDrawable = BitmapUtils.decodeBitmap(path, 100, 150)?.let { defaultDrawable = kotlin.runCatching {
BitmapDrawable(appCtx.resources, it) BitmapDrawable(appCtx.resources, BitmapUtils.decodeBitmap(path, 100, 150))
} ?: appCtx.resources.getDrawable(R.drawable.image_cover_default, null) }.getOrDefault(appCtx.resources.getDrawable(R.drawable.image_cover_default, null))
} }
fun getBlurDefaultCover(context: Context): RequestBuilder<Drawable> { fun getBlurDefaultCover(context: Context): RequestBuilder<Drawable> {

@ -28,7 +28,8 @@ object BitmapUtils {
* @param height 想要显示的图片的高度 * @param height 想要显示的图片的高度
* @return * @return
*/ */
fun decodeBitmap(path: String, width: Int, height: Int): Bitmap? { @Throws(IOException::class)
fun decodeBitmap(path: String, width: Int, height: Int): Bitmap {
val op = BitmapFactory.Options() val op = BitmapFactory.Options()
val ips = FileInputStream(path) val ips = FileInputStream(path)
// inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; // inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight;
@ -53,7 +54,8 @@ object BitmapUtils {
* @param path 图片路径 * @param path 图片路径
* @return * @return
*/ */
fun decodeBitmap(path: String): Bitmap? { @Throws(IOException::class)
fun decodeBitmap(path: String): Bitmap {
val opts = BitmapFactory.Options() val opts = BitmapFactory.Options()
val ips = FileInputStream(path) val ips = FileInputStream(path)
opts.inJustDecodeBounds = true opts.inJustDecodeBounds = true

Loading…
Cancel
Save