From 4647c8ecd2f8ba1d7e3403ea6cfca0cfe6fe19c5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 14 Apr 2022 11:32:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/utils/BitmapUtils.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt index 92bfff174..9fbba9c02 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt @@ -7,7 +7,6 @@ import android.graphics.* import android.graphics.Bitmap.Config import android.view.View import com.google.android.renderscript.Toolkit -import java.io.FileInputStream import java.io.IOException import kotlin.math.* @@ -27,10 +26,9 @@ object BitmapUtils { @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; op.inJustDecodeBounds = true - BitmapFactory.decodeFileDescriptor(ips.fd, null, op) + BitmapFactory.decodeFile(path, op) //获取比例大小 val wRatio = ceil((op.outWidth / width).toDouble()).toInt() val hRatio = ceil((op.outHeight / height).toDouble()).toInt() @@ -43,7 +41,7 @@ object BitmapUtils { } } op.inJustDecodeBounds = false - return BitmapFactory.decodeFileDescriptor(ips.fd, null, op) + return BitmapFactory.decodeFile(path, op) } /** 从path中获取Bitmap图片 @@ -53,12 +51,11 @@ object BitmapUtils { @Throws(IOException::class) fun decodeBitmap(path: String): Bitmap { val opts = BitmapFactory.Options() - val ips = FileInputStream(path) opts.inJustDecodeBounds = true - BitmapFactory.decodeFileDescriptor(ips.fd, null, opts) + BitmapFactory.decodeFile(path, opts) opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128) opts.inJustDecodeBounds = false - return BitmapFactory.decodeFileDescriptor(ips.fd, null, opts) + return BitmapFactory.decodeFile(path, opts) } /**