美文网首页
毛玻璃化

毛玻璃化

作者: eveo | 来源:发表于2016-07-15 10:40 被阅读109次

/**
* 对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();
    }
}

相关文章

网友评论

      本文标题:毛玻璃化

      本文链接:https://www.haomeiwen.com/subject/cudyjttx.html