Created
March 10, 2014 15:10
-
-
Save bdenney/9466812 to your computer and use it in GitHub Desktop.
This file contains 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
package com.bdenney.scfav.image; | |
import android.annotation.TargetApi; | |
import android.app.Activity; | |
import android.graphics.Bitmap; | |
import android.os.Build; | |
import android.renderscript.Allocation; | |
import android.renderscript.Element; | |
import android.renderscript.RenderScript; | |
import android.renderscript.ScriptIntrinsicBlur; | |
import com.squareup.picasso.Transformation; | |
/** | |
* {@link com.squareup.picasso.Transformation} for bluring the image using renderscript intrinsics. | |
*/ | |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) | |
public class BlurTransformer implements Transformation { | |
/** | |
* The activity to initialize the renderscript with. | |
*/ | |
private Activity mActivity; | |
/** | |
* Constructor. | |
* | |
* @param activity | |
* the activity to initialize the renderscript with. | |
*/ | |
public BlurTransformer(final Activity activity) { | |
mActivity = activity; | |
} | |
@Override | |
public String key() { | |
return "intrinsicBlur()"; | |
} | |
@Override | |
public Bitmap transform(Bitmap source) { | |
// Create an output bitmap by copying the source. | |
final Bitmap output = source.copy(Bitmap.Config.ARGB_8888, true); | |
RenderScript rs = RenderScript.create(mActivity); | |
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); | |
Allocation tmpIn = Allocation.createFromBitmap(rs, source); | |
Allocation tmpOut = Allocation.createFromBitmap(rs, output); | |
theIntrinsic.setRadius(1.f); | |
theIntrinsic.setInput(tmpIn); | |
theIntrinsic.forEach(tmpOut); | |
tmpOut.copyTo(output); | |
source.recycle(); | |
return output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment