This commit is contained in:
gedoor 2021-10-21 22:11:25 +08:00
parent 502cef4b04
commit fd5c9e0ec4
2 changed files with 7 additions and 5 deletions

View File

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

View File

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