From 4f5c969ed71ea4829cc3f923e82fc03b7bb3cd78 Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Sat, 24 Apr 2021 15:24:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80BitmapFactory.decodeStream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/utils/BitmapUtils.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 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 77b43f4de..78491d904 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt @@ -29,10 +29,10 @@ object BitmapUtils { fun decodeBitmap(path: String, width: Int, height: Int): Bitmap? { val op = BitmapFactory.Options() op.inPreferredConfig = Config.RGB_565 - val ips = FileInputStream(path) + var ips = FileInputStream(path) // inJustDecodeBounds如果设置为true,仅仅返回图片实际的宽和高,宽和高是赋值给opts.outWidth,opts.outHeight; op.inJustDecodeBounds = true - BitmapFactory.decodeFileDescriptor(ips.fd, null, op) + BitmapFactory.decodeStream(ips, null, op) //获取比例大小 val wRatio = ceil((op.outWidth / width).toDouble()).toInt() val hRatio = ceil((op.outHeight / height).toDouble()).toInt() @@ -45,7 +45,8 @@ object BitmapUtils { } } op.inJustDecodeBounds = false - return BitmapFactory.decodeFileDescriptor(ips.fd, null, op) + ips = FileInputStream(path) + return BitmapFactory.decodeStream(ips, null, op) } /** 从path中获取Bitmap图片 @@ -56,13 +57,14 @@ object BitmapUtils { val opts = BitmapFactory.Options() opts.inPreferredConfig = Config.RGB_565 - val ips = FileInputStream(path) + var ips = FileInputStream(path) opts.inJustDecodeBounds = true - BitmapFactory.decodeFileDescriptor(ips.fd, null, opts) + BitmapFactory.decodeStream(ips, null, opts) opts.inSampleSize = computeSampleSize(opts, -1, 128 * 128) opts.inJustDecodeBounds = false + ips = FileInputStream(path) - return BitmapFactory.decodeFileDescriptor(ips.fd, null, opts) + return BitmapFactory.decodeStream(ips, null, opts) } /**