Fresco of Android open source framework

Introduction

Fresco is Facebook's latest powerful image library for displaying images in Android applications. It can load images from the network, local storage and local resources. Compared with ImageLoader, it has many advantages such as faster picture download speed and the ability to load and display gif pictures. It is a good picture frame.

Features

  • Memory management: In systems below 5.0, Fresco puts pictures in a special memory area. Of course, when the picture is not displayed, the occupied memory will be automatically released. This will make the APP smoother and reduce OOM caused by image memory usage. Memory allocation adopts: system anonymous shared memory.
  • Shared memory is arguably the most useful method of inter-process communication and the fastest form of IPC. The shared memory of two different processes A and B means that the same piece of physical memory is mapped to the respective process address spaces of processes A and B. Process A can instantly see process B's update to the data in the shared memory, and vice versa. Since multiple processes share the same memory area, some kind of synchronization mechanism is inevitably required, both mutexes and semaphores are fine.
  • Progressive picture presentation: The progressive picture format first presents a rough picture outline, and then as the picture download continues, it presents a gradually clear picture, which is great for mobile devices, especially slow networks, and can bring better User experience. Supports loading Gif diagrams and WebP format.
  • The presentation of the image:
    1. Customize the center focus (very helpful for the display of pictures such as faces).
    2. Figure with rounded corners, of course a circle is also OK.
    3. After the download fails, click to download again.
    4. Custom placeholder map, custom overlay, or progress bar.
    5. Specify the overlay when the user presses.
  • Image loading:
    1. Specify a different remote path for the same picture, or use a picture that already exists in the local cache.
    2. Display a low-resolution picture first, and then display the high-definition picture after the high-definition picture is downloaded.
    3. Callback notification when loading is complete.
    4. For this map, if there is an EXIF ​​thumbnail, the thumbnail can be displayed before the large image is loaded.
    5. Zoom or rotate the picture.
    6. Process the downloaded pictures.

download link

  • https://github.com/facebook/fresco
  • Official website: http://fresco-cn.org/docs/index.html ( There are some cases in it, you can refer to it )

Supported URI

  • Remote picture http://, https://
  • Local file file://
  • Content provider content://
  • Asset asset:// in the asset directory
  • Resources res:// in the res directory
  • Specify picture data in Uri data: mime/type; base64

Common API

Insert picture description here
Insert picture description here

Steps for usage

  • Add dependency
dependencies {
    
    
  // 在 API < 14 上的机器支持 WebP 时时,需要添加
  compile 'com.facebook.fresco:animated-base-support:0.14.1'
  // 支持 GIF 动图时,需要添加
  compile 'com.facebook.fresco:animated-gif:0.14.1'
  // 支持 WebP (静态图+动图)时,需要添加
  compile 'com.facebook.fresco:animated-webp:0.14.1'
  compile 'com.facebook.fresco:webpsupport:0.14.1'
  // 仅支持 WebP 静态图时,需要添加
  compile 'com.facebook.fresco:webpsupport:0.14.1'
  //这个必须要添加
  compile 'com.facebook.fresco:fresco:0.14.1'
}
  • Initialize Fresco in the application
Fresco.initialize(this);
  • Configure network permissions
<uses-permission android:name="android.permission.INTERNET"/>
  • In the xml layout file, add the namespace
<!-- 其他元素-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"

    android:layout_height="match_parent"
    android:layout_width="match_parent">
  • Introduce SimpleDraweeView in the xml file
<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/my_image_view"
    android:layout_width="130dp"
    android:layout_height="130dp"

    fresco:placeholderImage="@drawable/my_drawable"
  />
  • Start loading the picture in the java file
//举例如下:
Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/logo.png");
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);

Insert picture description here
Demo site: https://github.com/hzulwy/private-project/blob/master/src.rar

Guess you like

Origin blog.csdn.net/qq_36828822/article/details/104087877