From 38b03be09b7b595e670de7aeba373b8f60214a37 Mon Sep 17 00:00:00 2001 From: unknown <318442028@qq.com> Date: Sun, 18 Dec 2016 22:16:50 +0800 Subject: [PATCH 1/3] Shrink bitmap before blur,then zoom bitmap after blured --- .../daimajia/androidviewhover/tools/Blur.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java b/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java index 2672c31..bac9362 100644 --- a/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java +++ b/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java @@ -1,6 +1,8 @@ package com.daimajia.androidviewhover.tools; + import android.graphics.Bitmap; import android.content.Context; +import android.graphics.Matrix; import android.support.v8.renderscript.Allocation; import android.support.v8.renderscript.Element; import android.support.v8.renderscript.RenderScript; @@ -10,12 +12,15 @@ public class Blur { private static final int DEFAULT_BLUR_RADIUS = 10; + private static final float DEFAULT_SCALE = 2; public static Bitmap apply(Context context, Bitmap sentBitmap) { - return apply(context, sentBitmap, DEFAULT_BLUR_RADIUS); + return apply(context, sentBitmap, DEFAULT_BLUR_RADIUS, DEFAULT_SCALE); } - public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) { + public static Bitmap apply(Context context, Bitmap sentBitmap, int radius, float scaleRadius) { + // shrink half + sentBitmap = scaleBitmap(sentBitmap, 1 / scaleRadius); final Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); final RenderScript rs = RenderScript.create(context); final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); @@ -26,13 +31,21 @@ public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) { script.setInput(input); script.forEach(output); output.copyTo(bitmap); - + //zoom bitmap + final Bitmap zoomBitmap = scaleBitmap(bitmap, scaleRadius); + bitmap.recycle(); sentBitmap.recycle(); rs.destroy(); input.destroy(); output.destroy(); script.destroy(); - return bitmap; + return zoomBitmap; + } + + public static Bitmap scaleBitmap(Bitmap oldBitmap, float scale) { + Matrix matrix = new Matrix(); + matrix.postScale(scale, scale); + return Bitmap.createBitmap(oldBitmap, 0, 0, oldBitmap.getWidth(), oldBitmap.getHeight(), matrix, true); } } \ No newline at end of file From ee639e59585e298fbafdd2a988c0ab59c984253f Mon Sep 17 00:00:00 2001 From: RosesJack Date: Sun, 18 Dec 2016 22:33:31 +0800 Subject: [PATCH 2/3] Update Blur.java Correct the error --- .../java/com/daimajia/androidviewhover/tools/Blur.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java b/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java index bac9362..7165fc7 100644 --- a/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java +++ b/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java @@ -18,9 +18,9 @@ public static Bitmap apply(Context context, Bitmap sentBitmap) { return apply(context, sentBitmap, DEFAULT_BLUR_RADIUS, DEFAULT_SCALE); } - public static Bitmap apply(Context context, Bitmap sentBitmap, int radius, float scaleRadius) { + public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) { // shrink half - sentBitmap = scaleBitmap(sentBitmap, 1 / scaleRadius); + sentBitmap = scaleBitmap(sentBitmap, 1 / DEFAULT_SCALE); final Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); final RenderScript rs = RenderScript.create(context); final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); @@ -32,7 +32,7 @@ public static Bitmap apply(Context context, Bitmap sentBitmap, int radius, float script.forEach(output); output.copyTo(bitmap); //zoom bitmap - final Bitmap zoomBitmap = scaleBitmap(bitmap, scaleRadius); + final Bitmap zoomBitmap = scaleBitmap(bitmap, DEFAULT_SCALE); bitmap.recycle(); sentBitmap.recycle(); rs.destroy(); @@ -48,4 +48,4 @@ public static Bitmap scaleBitmap(Bitmap oldBitmap, float scale) { matrix.postScale(scale, scale); return Bitmap.createBitmap(oldBitmap, 0, 0, oldBitmap.getWidth(), oldBitmap.getHeight(), matrix, true); } -} \ No newline at end of file +} From 0e330b2fb91e54b58e1e3b724e7b111be188f615 Mon Sep 17 00:00:00 2001 From: RosesJack Date: Mon, 19 Dec 2016 09:21:41 +0800 Subject: [PATCH 3/3] Correct the error Correct the error --- .../src/main/java/com/daimajia/androidviewhover/tools/Blur.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java b/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java index 7165fc7..4976fad 100644 --- a/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java +++ b/library/src/main/java/com/daimajia/androidviewhover/tools/Blur.java @@ -15,7 +15,7 @@ public class Blur { private static final float DEFAULT_SCALE = 2; public static Bitmap apply(Context context, Bitmap sentBitmap) { - return apply(context, sentBitmap, DEFAULT_BLUR_RADIUS, DEFAULT_SCALE); + return apply(context, sentBitmap, DEFAULT_BLUR_RADIUS); } public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) {