facebook强大的图片加载工具Fresco,比imageload加载速度快


关于 Fresco
Fresco 是一个强大的图片加载组件。
Fresco 中设计有一个叫做 image pipeline 的模块。它负责从网络,从本地文件系统,本地资源加载图片。为了最大限度节省空间和CPU时间,它含有3级缓存设计(2级内存,1级文件)。
Fresco 中设计有一个叫做 Drawees 模块,方便地显示loading图,当图片不再显示在屏幕上时,及时地释放内存和空间占用。
Fresco 支持 Android2.3(API level 9) 及其以上系统。
特性内存管理

一个没有未压缩的图片,即Android中的Bitmap,占用大量的内存。大的内存占用势必引发更加频繁的GC。在5.0以下,GC将会显著地引发界面卡顿。
在5.0以下系统,Fresco将图片放到一个特别的内存区域。当然,在图片不显示的时候,占用的内存会自动被释放。这会使得APP更加流畅,减少因图片内存占用而引发的OOM。
Fresco 在低端机器上表现一样出色,你再也不用因图片内存占用而思前想后。


经过一天的努力,终于弄出了eclipse版本。只需要引用lib就可以实现你想要的图片加载


初始化配置的两种方式:
                 * 在 Application 初始化时,在应用调用 setContentView() 之前,进行初始化:
                 * Fresco.initialize(context);

public static void initConfig(Context context) {
                        ImagePipelineConfig initImagePipelineConfig = initImagePipelineConfig(context);
                        Fresco.initialize(context, initImagePipelineConfig);
                }
                        
                public static ImagePipelineConfig initImagePipelineConfig(Context context) {
                        if (sImagePipelineConfig == null) {
                                sImagePipelineConfig = configureCaches(context);
                        }
                        return sImagePipelineConfig;
                }




使用起来也是超级方便的,根据自己的需求随意配置XML文件属性

<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/my_image_view"
            android:layout_width="20dp"   // 不支持wrap_content 如果要设置宽高比, 需要在Java代码中指定setAspectRatio(1.33f);
            android:layout_height="20dp"    // 不支持wrap_content 
            fresco:fadeDuration="300"
            
            fresco:actualImageScaleType="focusCrop"// 设置图片缩放. 通常使用focusCrop,该属性值会通过算法把人头像放在中间
            fresco:placeholderImage="@color/wait_color"// 下载成功之前显示的图片
         
            fresco:placeholderImageScaleType="fitCenter"
            fresco:failureImage="@drawable/error"// 加载失败的时候显示的图片
        
            fresco:failureImageScaleType="centerInside"
            fresco:retryImage="@drawable/retrying"// 加载失败,提示用户点击重新加载的图片(会覆盖failureImage的图片)
        
            fresco:retryImageScaleType="centerCrop"
            fresco:progressBarImage="@drawable/progress_bar"// 提示用户正在加载,和加载进度无关
            
            fresco:progressBarImageScaleType="centerInside"
            fresco:progressBarAutoRotateInterval="1000"
            fresco:backgroundImage="@color/blue"
            fresco:overlayImage="@drawable/watermark"
            fresco:pressedStateOverlayImage="@color/red"
            
            fresco:roundAsCircle="false"// 是不是设置圆圈
        
            fresco:roundedCornerRadius="1dp"// 圆角角度,180的时候会变成圆形图片
            
            fresco:roundTopLeft="true"
            fresco:roundTopRight="false"
            fresco:roundBottomLeft="false"
            fresco:roundBottomRight="true"
            fresco:roundWithOverlayColor="@color/corner_color"
            fresco:roundingBorderWidth="2dp"
            fresco:roundingBorderColor="@color/border_color"
                  />




加载图片非常方便的
/**
         * 加载图片(默认加载中占位图)
         * @param draweeView 控件
         * @param uriString 地址
         */
        public static void loadImage(SimpleDraweeView draweeView , String uriString) {
                Uri uri = Uri.parse(uriString);
                GenericDraweeHierarchy hierarchy = draweeView.getHierarchy();
                hierarchy.setPlaceholderImage(R.drawable.pic10);//修改占位图为资源
                hierarchy.setActualImageScaleType(ScaleType.CENTER_INSIDE);//修改缩放类型
                draweeView.setHierarchy(hierarchy);
                draweeView.setImageURI(uri);
        }
        
        /**
         * 加载图片(无占位图)
         * @param draweeView 控件
         * @param uriString 地址
         */
        public static void loadImg(SimpleDraweeView draweeView , String uriString ) {
                Uri uri = Uri.parse(uriString);
                draweeView.setImageURI(uri);
        }


很多属性都是 可以自定义的,这样子就给我们的工作带来了很大的方便

下载之后有不明白的可以跟帖或是邮件  zbl704@yeah.net


点击打开链接

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值