图片框架Fresco

1.首先加入依赖

implementation 'com.facebook.fresco:fresco:1.11.0'
implementation 'com.facebook.fresco:animated-gif:1.11.0'

2.配置Application

 @Override
    public void onCreate() {
        super.onCreate();
        //Fresco.initialize(this );
        Fresco.initialize(this, ImagePipelineConfig.newBuilder(App.this)
                .setMainDiskCacheConfig(
                        DiskCacheConfig.newBuilder(this)
                                .setBaseDirectoryPath(new File(Environment.getExternalStorageDirectory().getAbsolutePath())) // 注意Android运行时权限。
                                .build()
                )
                .build()
        );
    }
3.mainactivity
public class MainActivity extends AppCompatActivity {
    private String imageUrl="https://img.huxiucdn.com/article/cover/201810/29/153108448766.jpg";
    private SimpleDraweeView simpla_view;
    private String URL_="https://img3.duitang.com/uploads/item/201605/14/20160514165650_RHr3n.gif";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        simpla_view = findViewById(R.id.simpla_view);
        simpla_view.setImageURI("https://img.huxiucdn.com/article/cover/201810/29/153108448766.jpg");
        /*Uri uri = Uri.parse("res://com.example.week22/" + R.mipmap.ic_launcher);
        simpla_view.setImageURI(uri);*/
        //showUrlBlur(simpla_view,imageUrl,100,10);
        AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
                //图片地址
                .setUri(imageUrl)
                //播放gif 图片
                .setAutoPlayAnimations(true)
                //点击重新加载时 可以重新加载4 次
                .setTapToRetryEnabled(true)
                .build();
        simpla_view.setController(controller);

    }

    public  void showUrlBlur(SimpleDraweeView draweeView, String url, int iterations, int blurRadius) {
        try {
            Uri uri = Uri.parse(url);
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                    .setPostprocessor(new IterativeBoxBlurPostProcessor(iterations, blurRadius))
                    .build();
            AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
                    .setOldController(draweeView.getController())
                    .setImageRequest(request)
                    .build();
            draweeView.setController(controller);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值