【发布时间】:2017-12-22 07:28:26
【问题描述】:
我想做这样的事情
我尝试使用 Picaso,但没有得到任何有价值的解决方案
这是我的代码
String url ="http://static.tvtropes.org/pmwiki/pub/images/stephen_amell.png";
Picasso.with(getActivity()).load(url)
.transform(new BlurTransformation(getActivity()))
.into(imgBlurImage);
BlurTransformation.java
public class BlurTransformation implements Transformation {
RenderScript rs;
private static final int RADIUS = 10;
public BlurTransformation(Context context) {
super();
rs = RenderScript.create(context);
}
@Override
public Bitmap transform(Bitmap bitmap) {
// Create another bitmap that will hold the results of the filter.
Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
// Allocate memory for Renderscript to work with
Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL,
Allocation.USAGE_SHARED);
Allocation output = Allocation.createTyped(rs, input.getType());
// Load up an instance of the specific script that we want to use.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setInput(input);
// Set the blur radius
script.setRadius(RADIUS);
// Start the ScriptIntrinisicBlur
script.forEach(output);
}
// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
bitmap.recycle();
return blurredBitmap;
}
@Override
public String key() {
return "blur";
}
}
【问题讨论】:
-
你能贴出图片来说明你的实际结果吗?
-
@Hai Hack 请检查我编辑的答案
-
请包含xml文件
-
使宽度匹配父项
-
为什么不以编程方式拒绝它?
标签: android picasso uiblureffect