Android Fresco图片处理库用法API英文原文文档4(Facebook开源Android图片库)

这是英文文档的第三部分:THIRD PARTY LIBRARIES

Using Other Network Layers

By default, the image pipeline uses the HttpURLConnection networking library
bundled with Android. Apps may have their own network layer they may wish to use instead.

Using OkHttp

OkHttp is a popular open-source networking library. The image pipeline has a backend that uses OkHttp instead of the Android
default.

In order to use it, the dependencies section of your build.gradle file needs to be changed. Donot use
the Gradle dependencies given on the download page. Use these instead:

dependencies {
  // your project‘s other dependencies
  compile "com.facebook.fresco:fresco:0.2.0+"
  compile "com.facebook.fresco:imagepipeline-okhttp:0.2.0+"
}

You must also configure the image pipeline a little differently. Instead of usingImagePipelineConfig.newBuilder, use OkHttpImagePipelineConfigFactory instead:

Context context;
OkHttpClient okHttpClient; // build on your own
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
    .newBuilder(context, okHttpClient)
    . // other setters
    . // setNetworkFetcher is already called for you
    .build();
Fresco.initialize(context, config);

Using your own network fetcher (optional)

For complete control on how the networking layer should behave, you can provide one for your app. You must subclass NetworkFetcher,
which controls communications to the network. You can also optionally subclass FetchState,
which is a data structure for request-specific information.

Our default implementation for HttpURLConnection can be used as an example. See its
source code
.

You must pass your network producer to the image pipeline when configuring it:

ImagePipelineConfig config = ImagePipelineConfig.newBuilder()
  .setNetworkFetcher(myNetworkFetcher);
  . // other setters
  .build();
Fresco.initialize(context, config);

Using Other Image Loaders

Drawee is not tied to a particular image loading mechanism and can be used with other image loaders.

However, some of its features are only available on the Fresco image pipeline. Any feature in the preceding pages that required using an ImageRequest or configuration may
not work with a different loader.

Using Drawee with Volley ImageLoader

We have an backend for Drawee that allows Volley‘s ImageLoader to be used instead of Fresco‘s
image pipeline.

We only recommend this for apps that already have a significant investment in Volley ImageLoader.

In order to use it, the dependencies section of your build.gradle file needs to be changed. Donot use
the Gradle dependencies given on the download page. Use this instead:

dependencies {
  // your project‘s other dependencies
  compile: "com.facebook.fresco:drawee-volley:0.2.0+"
}

Initializing with Volley ImageLoader

Do not call Fresco.initialize. You must do yourself for Volley what it does with the image pipeline:

Context context;
ImageLoader imageLoader; // build yourself
VolleyDraweeControllerBuilderSupplier mControllerBuilderSupplier
    = new VolleyDraweeControllerBuilderSupplier(context, imageLoader);
SimpleDraweeView.initialize(mControllerBuilderSupplier);

Do not let the VolleyDraweeControllerBuilderSupplier out of scope; you need it to build controllers, unless you always use SimpleDraweeView.setImageURI.

Using DraweeControllers with Volley ImageLoader

Instead of calling Fresco.newControllerBuilder, call

VolleyController controller = mControllerBuilderSupplier
    .newControllerBuilder()
    . // setters
    .build();
mSimpleDraweeView.setController(controller);

Using Drawee with other image loaders

No other Drawee backends have been built yet, though it is possible to do so using the Volley
example
 as a model.

第5部分:CONTRIBUTING TO FRESCO

Building from Source

You should only build from source if you need to modify Fresco code itself. Most applications should simply include Fresco
in their project.

Prerequisites

The following tools must be installed on your system in order to build Fresco:

  1. The Android SDK
  2. From the Android SDK Manager, install the Support Library and the Support Repository. Both are found in the Extras section.
  3. The Android NDK. Version 10c or later is required.
  4. The git version control system.

You don‘t need to download Gradle itself; the build scripts or Android Studio will do that for you.

Fresco does not support source builds with Eclipse, Ant, or Maven. We do not plan to ever add such support. Maven projects can still include Fresco,
and we hope to later add Eclipse and Ant support.

Configuring Gradle

Both command-line and Android Studio users need to edit the gradle.properties file. This is normally located in your home directory, in a subdirectory called .gradle.
If it is not already there, create it.

On Unix-like systems, including Mac OS X, add a line like this:

ndk.path=/path/to/android_ndk/r10d

On Windows systems, add a line like this:

ndk.path=C\:\\path\\to\\android_ndk\\r10d

Windows‘ backslashes and colons need to be escaped in order for Gradle to read them correctly.

Getting the source

git clone https://github.com/facebook/fresco.git

This will create a directory fresco where the code will live.

Building from the Command Line

On Unix-like systems, cd to the directory containing Fresco. Run the following command:

./gradlew build

On Windows, open a Command Prompt, cd to the directory containing Fresco, and type in this command:

gradlew.bat build

Building from Android Studio

From Android Studio‘s Quick Start dialog, click Import Project. Navigate to the directory containing Fresco and click on the build.gradle file.

Android Studio should build Fresco automatically.

Offline builds

The first time you build Fresco, your computer must be connected to the Internet. Incremental builds can use Gradle‘s --offline option.

Contributing code upstream

Please see our CONTRIBUTING page.

时间: 2024-07-29 22:09:20

Android Fresco图片处理库用法API英文原文文档4(Facebook开源Android图片库)的相关文章

Android Fresco图片处理库用法API英文原文文档2-2(Facebook开源Android图片库)

Android Fresco图片处理库用法API英文原文文档2-2(Facebook开源Android图片库) 这是英文文档的第二部分(2):DRAWEE GUIDE 由于第二部分内容多一些,所以分为2个文章发.方便大家查看. Using the ControllerBuilder SimpleDraweeView has two methods for specifying an image. The easy way is to just callsetImageURI. If you wa

Android Fresco图片处理库用法API英文原文文档1(Facebook开源Android图片库)

Fresco是Facebook最新推出的一款用于Android应用中展示图片的强大图片库,可以从网络.本地存储和本地资源中加载图片.其中的Drawees可以显示占位符,直到图片加载完成.而当图片从屏幕上消失时,会自动释放内存. 功能很强大,为了大家学习方便,我将英文原文文档给大家迁移过来,供参考学习. 这是英文文档的第一部分:QUICK START QUICK START Adding Fresco to your Project Here's how to add Fresco to your

Android Fresco图片处理库用法API英文原文文档3(Facebook开源Android图片库)

这是英文文档的第三部分:IMAGE PIPELINE GUIDE Introduction to the Image Pipeline The image pipeline does everything necessary to get an image into a form where it can be rendered into an Android device. The pipeline goes through the following steps when given an

Android Fresco图片处理库用法API英文原文文档2-1(Facebook开源Android图片库)

这是英文文档的第二部分(1):DRAWEE GUIDE 由于第二部分内容多一些,所以分为2个文章发.方便大家查看. Using Drawees in XML Drawees have very extensive customization facilities. The best way to customize your Drawee is to do so in the XML. Here is an example that sets nearly all possible option

Android 一起来看看知乎开源的图片选择库

前言 在实际开发中,图片选择器一直都是必不可少的一个部分,不管是 QQ 头像的设置,还是发送一条装逼的微信朋友圈,都要用到图片选择器来给用户选择他们想要上传的图片,最近知乎开源了一款图片选择库 Matisse 简直美哭了,而且完全遵循 Android 交互设计规范,实在是很良心. 在开始正文之前,先欣赏一下这个图片选择器的效果 是不是感觉相当的简洁好看,反正我是这么认为的. 一.基本使用 1.导入相应的依赖库 Gradle: repositories { jcenter() } dependen

Android 解决图片大量下载:软引用必须懂4点

Android 解决图片大量下载:软引用必须懂4点 可能对于Android开发者来说,软引用这个词有的会不是很熟悉,软引用在Java开发中用的比较多,但是,在Android开发中引用软引用,会给我们解决很多难题. AD: 1.对象的强.软.弱和虚引用 为了能更加灵活控制对象的生命周期,需要知道对象引用的4中级别,由高到低依次为 :强引用.软引用.弱引用和虚引用 备注: 这四种的区别: ⑴强引用(StrongReference) 强引用是使用最普遍的引用.如果一个对象具有强引用,那垃圾回收器绝不会

Universal-Image-Loader,android-Volley,Picasso、Fresco和Glide图片缓存库的联系与区别

Universal-Image-Loader,android-Volley,Picasso.Fresco和Glide五大Android开源组件加载网络图片比较 在Android中的加载网络图片是一件十分令人头疼的事情,在网上有着许多关于加载网络图片的开源库,可以让我们十分方便的加载网络图片.在这里介绍一下Universal-Image-Loader,android-Volley,Picasso.Fresco和Glide的一些使用以及最基本的用法介绍. 1. // imageView是一个Imag

Android图片剪裁库

最近利用一周左右的业余时间,终于完成了一个Android图片剪裁库,核心功能是根据自己的理解实现的,部分代码参考了Android源码的图片剪裁应用.现在将该代码开源在Github上以供大家学习和使用,地址:https://github.com/Jhuster/ImageCropper,效果如下所示: 我的大致计划是首先介绍一下这个库的用法,然后再写几篇文章介绍一下其中的一些原理和关键技术,希望对Android开发新手有所帮助. [特性] 支持通过手势移动和缩放剪裁窗口 支持固定剪裁窗口大小.固定

Android压缩图片和libjpeg库

前言 Fjpeg使用 Fjpeg 注意 如何使用 如何压缩图片只改变在硬盘的存储大小 如何改变图片分辨率让其Bitmap对象可以加载到内存中 关于重载版本 开始学习之旅 补充知识的结论 修改图片分辨率 防止在Android加载Bitmap的时候oom内存溢出 解决方案1 解决方案2 希望压缩图片方便网络传输 第一种方案利用Bitmapcompress方法压缩 第二种利用libjpeg压缩 在Android50测试两个 图片压缩 在Android60测试两个 图片压缩 解释Android50和60