来自非死book强大Android图片展示系统:Fresco

jopen 10年前

Fresco是一个强大的系统用于在Android应用中展示图片。它负责图片的加载和展示,所以你不做任何事情。

Fresco能够从网络中,本地存储或本地资源加载图片。为节省数据和CPU,它拥有三级缓存:两级在内存中,加一个在外部存储。
Fresco的Drawees 能够显示占位符,直到你的图片已加载,并自动显示到图像时到达。当图像从屏幕消失时,它会自动释放内存。

Fresco 支持Android 2.3 (Gingerbread) 以上的版本。
来自非死book强大Android图片展示系统:Fresco

特性

Memory

A decompressed image - an AndroidBitmap- takes up a lot of memory. This leads to more frequent runs of the Java garbage collector. This slows apps down. The problem is especially bad without the improvements to the garbage collector made in Android 5.0.

On Android 4.x and lower, Fresco puts images in a special region of Android memory. It also makes sure that images are automatically released from memory when they're no longer shown on screen. This lets your application run faster - and suffer fewer crashes.

Apps using Fresco can run even on low-end devices without having to constantly struggle to keep their image memory footprint under control.

Streaming

Progressive JPEG images have been on the Web for years. These let a low-resolution scan of the image download first, then gradually improve the quality as more of the image downloads. This is a lifesaver for users on slow networks.

Android's own imaging libraries don't support streaming. Fresco does. Just specify a URI, and your app will automatically update its display as more data arrives.

Animations

Animated GIFs and WebPs can be challenging for apps. Each frame is a large Bitmap, and each animation is a series of frames. Fresco takes care of loading and disposing of frames and managing their memory.

Drawing

Fresco usesDraweesfor display. These offer a number of useful features:

  • Scale the image to a custom focus point, instead of the centre
  • Show the image with rounded corners, or a circle
  • Let users tap the placeholder to retry load of the image, if the network load failed
  • Show custom backgrounds, overlays, or progress bars on the image
  • Show a custom overlay when the user presses the image

Loading

Fresco's image pipeline lets you customize the load in a variety of ways:

  • Specify several different uris for an image, and choose the one already in cache for display
  • Show a low-resolution image first and swap to a higher-res one when it arrives
  • Send events back into your app when the image arrives
  • If the image has an EXIF thumbnail, show it first until the full image loads (local images only)
  • Resize or rotate the image
  • Modify the downloaded image in-place
  • Decode WebP images, even on older versions of Android that don't fully support them
draweeView.setImageURI("http://site.com/uri");

项目主页:http://www.open-open.com/lib/view/home/1427441643621