FrescoUtil工具类:


import android.net.Uri;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.generic.RoundingParams;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;

public class FrescoUtil {
    /**
     * 基础加载图片
     * @param url 图片路径
     * @param simpleDraweeView 控件
     */
    public static void setTu(String url,SimpleDraweeView simpleDraweeView){
        Uri uri = Uri.parse(url);
        simpleDraweeView.setImageURI(uri);
    }
    /**
     * 渐进式加载图片
     * @param url 图片路径
     * @param simpleDraweeView 控件
     */
    public static void setJianJin(String url, SimpleDraweeView simpleDraweeView){
        Uri uri = Uri.parse(url);
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                .setProgressiveRenderingEnabled(true)
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(simpleDraweeView.getController())
                .build();
        simpleDraweeView.setController(controller);
    }
    /**
     * 圆角图片
     * @param url 图片路径
     * @param simpleDraweeView 控件
     * @param radius 角度
     * @param color 描边线颜色
     * @param width  描边线宽度
     */
    public static void setYuanJiao(String url,SimpleDraweeView simpleDraweeView,float radius,int color,float width){
        Uri uri = Uri.parse(url);
        RoundingParams roundingParams = RoundingParams.fromCornersRadius(0f);
        if (width > 0f) {
            roundingParams.setBorder(color, width);//描边线
        }
        roundingParams.setCornersRadius(radius);//总体圆角
        simpleDraweeView.getHierarchy().setRoundingParams(roundingParams);
        simpleDraweeView.setImageURI(uri);
    }

    /**
     * 圆角图片
     * 可控四角角度
     * @param url 图片路径
     * @param simpleDraweeView 控件
     * @param topLeft 左上角
     * @param topRight 右上角
     * @param bottomRight 右下角
     * @param bottomLeft 左下角
     * @param color 描边线颜色
     * @param width 描边线宽度
     */
    public static void setYuanJiao(String url,SimpleDraweeView simpleDraweeView,float topLeft, float topRight, float bottomRight, float bottomLeft,int color,float width){
        Uri uri = Uri.parse(url);
        RoundingParams roundingParams = RoundingParams.fromCornersRadius(0f);
        if (width > 0f) {
            roundingParams.setBorder(color, width);//描边线
        }
        roundingParams.setCornersRadii(topLeft,topRight,bottomRight,bottomLeft);//各角不同圆角
        simpleDraweeView.getHierarchy().setRoundingParams(roundingParams);
        simpleDraweeView.setImageURI(uri);
    }

    /**
     * 圆形图片
     * @param url 图片路径
     * @param simpleDraweeView 控件
     * @param color 描边线颜色
     * @param width 描边线宽度
     */
    public static void setYuanQuan(String url,SimpleDraweeView simpleDraweeView,int color,float width){
        if(url==null){
            simpleDraweeView.setImageURI(url);
            return;
        }
        Uri uri = Uri.parse(url);
        RoundingParams roundingParams = RoundingParams.fromCornersRadius(0f);
        if (width > 0f) {
            roundingParams.setBorder(color, width);//描边线
        }
        roundingParams.setRoundAsCircle(true);//圆形
        simpleDraweeView.getHierarchy().setRoundingParams(roundingParams);
        simpleDraweeView.setImageURI(uri);
    }

    /**
     * Gif动态图片
     * @param url 图片路径
     * @param simpleDraweeView 控件
     */
    public static void setDongTu(String url,SimpleDraweeView simpleDraweeView){
        Uri uri = Uri.parse(url);
        DraweeController controller1 = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setTapToRetryEnabled(true)
                .setAutoPlayAnimations(true)//设置为true将循环播放Gif动画
                .setOldController(simpleDraweeView.getController())
                .build();
        simpleDraweeView.setController(controller1);
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
<h4>Fresco 的封装,快速上手,图像后处理,超大图高清预览,缩小放大,双击放大等一一俱全。</h4> ====================== [![](https://jitpack.io/v/CarGuo/FrescoUtils.svg)](https://jitpack.io/#CarGuo/FrescoUtils) [![Build Status](https://travis-ci.org/CarGuo/FrescoUtils.svg?branch=master)](https://travis-ci.org/CarGuo/FrescoUtils) ## 因为某些原因,现在使用jitpack.io,还请使用依赖的各位切换到jitpack。 #### 在project下的build.gradle添加 ``` allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` #### 在module下的build.gradle添加 ``` dependencies { compile 'com.github.CarGuo:FrescoUtils:v1.0.8' } ``` * 1.0.8 update fresco to 1.5.0 * 1.0.7 增加option配置方法; ``` /** * @param imageView 图片加载控件 * @param loadOption 加载配置构造器 */ public static void loadFrescoImage(FrescoImageView imageView, LoadOption loadOption) ``` * 1.0.6 update fresco to 1.3.0; * 1.0.5 update fresco to 1.2.0;移除无用依赖; * 1.0.4 update fresco to 1.0.1,update scaleImage to 3.6.0 * 1.0.3 update fresco to 1.0.0 * 1.0.2 最低API调整到15 * 1.0.1 增加了额FrescoHelper直接超大图加载接口 ``` /** * 超大图片的就接口 * * @param context 上下玩 * @param imageView 图片加载控件 * @param imageUri 图片地址 * @param defaultId 默认失败图片 */ public static void loadBigImage(final Context context, final SubsamplingScaleImageView imageView, String imageUri, final int defaultId) ``` <h4><a href="http://www.jianshu.com/p/cd058a924288">简书入口 这里有详细介绍</a></h4> ## 效果显示 <img src="https://github.com/CarGuo/FrescoUtils/blob/master/01.jpg" width="240px" height="426px"/> <img src="https://github.com/CarGuo/FrescoUtils/blob/master/02.jpg" width="240px" height="426px"/> <p></p> ### 动态图效果 <img src="https://github.com/CarGuo/FrescoUtils/blob/master/01.gif" width="240px" height="426px"/> <img src="https://github.com/CarGuo/FrescoUtils/blob/master/02.gif" width="240px" height="426px"/> <p></p> ### 记得记得在Application里初始化 ``` ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setDownsampleEnabled(true) .build(); Fresco.initialize(this, config); ``` ### FrescoHelper 封装了针对 <a href="https://github.com/HomHomLin/FrescoImageView">FrescoImageView</a> 的工具类,直接使用FrescoImageView作为ImageView使用即可。 封装了多种类型,这是最全的一种 ``` /** * @param imageView 图片加载控件 * @param uri 路径或者URL * @param defaultImg 默认图片 * @param cornerRadius 弧形角度 * @param isCircle 是否为圆 * @param loadLocalPath 是否本地资源,如果显示R.drawable.xxx,Path可以为null,前提isCircle为true * @param isAnima 是否显示GIF动画 * @param size 是否再编码 * @param postprocessor 图像显示处理 */ public static void loadFrescoImage(FrescoImageView imageView, String uri, int defaultImg, int cornerRadius, boolean isCircle, boolean loadLocalPath, boolean isAnima, Point size, Postprocessor postprocessor) { init(imageView, cornerRadius, isCircle, isAnima, size, postprocessor); if (loadLocalPath) { imageView.loadLocalImage(uri, defaultImg); } else { imageView.loadView(uri, defaultImg); } } ··· FrescoHelper.loadFrescoImage(frescoImageView, recyclerDataModel.getUrl(), R.mipmap.ic_launcher, 2, false, recyclerDataModel.getSize(), new BlurPostprocessor(context, 10)); ``` ### 带有<a href="https://github.com/wasabeef/fresco-processors">fresco-processors</a>各种处理特效,高斯,五角形等。 <img src="https://github.com/wasabeef/fresco-processors/raw/master/art/demo.gif" width="240px" height="426px"/> ### 带有<a href="https://github.com/davemorrissey/subsampling-scale-image-view">subsampling-scale-image-view</a>实现超高清图片超长图片不模糊显示。 <img src="https://github.com/CarGuo/FrescoUtils/blob/master/01.gif" width="240px" height="426px"/> ### 带有<a href="https://github.com/ongakuer/PhotoDraweeView">PhotoDraweeView</a> 功能与PhotoView一样,支持双击放大,单击返回,手动放大与缩小等。 <img src="https://github.com/ongakuer/PhotoDraweeView/raw/master/screenshot.gif" width="240px" height="426px"/>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值