Created
January 4, 2015 02:07
-
-
Save dzwillpower/6064d8ef9ea6f6c07c8f to your computer and use it in GitHub Desktop.
图片高斯模糊
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Blur a bitmap by specified radius | |
* @param context | |
* @param src | |
* @param radius | |
* @return | |
*/ | |
public static Bitmap blurBitmap(Context context, Bitmap src, float radius) | |
throws RSIllegalArgumentException { | |
if (radius <= 0f) { | |
return src; | |
} else if (radius > 25f) { | |
throw new RSIllegalArgumentException("Radius out of range (0 < r <= 25)."); | |
} | |
MyLog.d(TAG, "bitmap width: "+src.getWidth()+"bitmap height: "+src.getHeight()); | |
Bitmap bluredBitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); | |
RenderScript renderScript = RenderScript.create(context); | |
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(renderScript, | |
Element.U8_4(renderScript)); | |
Allocation memorySrc = Allocation.createFromBitmap(renderScript, src); | |
Allocation memoryBlur = Allocation.createFromBitmap(renderScript, bluredBitmap); | |
blurScript.setRadius(radius); | |
blurScript.setInput(memorySrc); | |
blurScript.forEach(memoryBlur); | |
memoryBlur.copyTo(bluredBitmap); | |
renderScript.destroy(); | |
return bluredBitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment