/**
* 对simpleDraweeView进行模糊效果
**/
public static void doSimpleDraweeViewBlur(Uri uri, SimpleDraweeView simpleDraweeView) {
if (null == uri) return;
Postprocessor redMeshPostprocessor = new BasePostprocessor() {
public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap(
sourceBitmap.getWidth(),
sourceBitmap.getHeight());
try {
Bitmap destBitmap = bitmapRef.get();
for (int x = 0; x < destBitmap.getWidth(); x++) {
for (int y = 0; y < destBitmap.getHeight(); y++) {
destBitmap.setPixel(x, y, sourceBitmap.getPixel(x, y));
}
}
FastBlur.doBlur(destBitmap, 2, true);
return CloseableReference.cloneOrNull(bitmapRef);
} finally {
CloseableReference.closeSafely(bitmapRef);
}
}
};
int width = simpleDraweeView.getWidth() / 8;
int height = simpleDraweeView.getHeight() / 8;
try {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
.setResizeOptions(new ResizeOptions(width, height))
.setPostprocessor(redMeshPostprocessor)
.build();
PipelineDraweeController controller = (PipelineDraweeController)
Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setOldController(simpleDraweeView.getController())
.build();
simpleDraweeView.setController(controller);
} catch (Exception e) {
e.printStackTrace();
}
}