From 6da0f994d63eb499536e05ba0b0b5afc6987fc60 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 5 Nov 2019 18:46:47 +0800 Subject: [PATCH] up --- .../io/legado/app/help/BlurTransformation.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BlurTransformation.kt b/app/src/main/java/io/legado/app/help/BlurTransformation.kt index 4d19a47a8..fec7d0eef 100644 --- a/app/src/main/java/io/legado/app/help/BlurTransformation.kt +++ b/app/src/main/java/io/legado/app/help/BlurTransformation.kt @@ -13,16 +13,23 @@ import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool import com.bumptech.glide.load.resource.bitmap.BitmapTransformation import java.security.MessageDigest +import kotlin.math.min +import kotlin.math.roundToInt + /** * 模糊 + * @radius: 0..25 */ -class BlurTransformation(val context: Context, private val radius: Int) : BitmapTransformation() { +class BlurTransformation(context: Context, private val radius: Int) : BitmapTransformation() { + private val rs: RenderScript = RenderScript.create(context) @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap { - val blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true) - val rs: RenderScript = RenderScript.create(context) + //图片缩小1/2 + val width = (min(outWidth, toTransform.width) / 2f).roundToInt() + val height = (min(outHeight, toTransform.height) / 2f).roundToInt() + val blurredBitmap = Bitmap.createScaledBitmap(toTransform, width, height, false); // Allocate memory for Renderscript to work with //分配用于渲染脚本的内存 val input = Allocation.createFromBitmap( @@ -39,7 +46,7 @@ class BlurTransformation(val context: Context, private val radius: Int) : Bitmap script.setInput(input) // Set the blur radius - //设置模糊半径 + //设置模糊半径0..25 script.setRadius(radius.toFloat()) // Start the ScriptIntrinsicBlur @@ -49,7 +56,6 @@ class BlurTransformation(val context: Context, private val radius: Int) : Bitmap // Copy the output to the blurred bitmap //将输出复制到模糊的位图 output.copyTo(blurredBitmap) - rs.destroy() return blurredBitmap }