Tuesday, November 7, 2017

Fresco

Fresco:

Hi Guys! now we are going to see about Fresco !!!!!!


  • Fresco is a powerful system for displaying images in android applications,It takes care of image loading and display,
  • Fresco supports android2.3 and later.
  • For Images Fresco can load it from network, local storage or local resources. To save data and CPU,
  • it has three levels of cache; one in internal storage and two in memory.


Features
  • Memory
  • Drawing
  • Animations
  • Loading
  • Streaming

1.Memory

A decompressed image - an Android Bitmap - 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.

2.Drawing


Fresco uses Drawees for display. These offer a number of useful features:

Scale the image to a custom focus point, instead of the center
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.

3.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.

4.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.

5.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.

Getting started with Fresco

Step 1

In your build.gradle file.
dependencies {
  // your app's other dependencies
  compile 'com.facebook.fresco:fresco:1.5.0'
}

optional modules may also be added:

// For animated GIF support
  compile 'com.facebook.fresco:animated-gif:1.5.0'

  // For WebP support, including animated WebP
  compile 'com.facebook.fresco:animated-webp:1.5.0'
  compile 'com.facebook.fresco:webpsupport:1.5.0'

  // For WebP support, without animations
  compile 'com.facebook.fresco:webpsupport:1.5.0'

  // Provide the Android support library (you might already have this or a similar dependency)
  compile 'com.android.support:support-core-utils:24.2.1'

Step 2

Initialize Fresco

@Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
    }

Step 3

In the AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

Step 4

add a custom namespace to the top-level element.

<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"
    >

Step 5

Then add the SimpleDraweeView to the layout

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/my_image_view"
    android:layout_width="130dp"
    android:layout_height="130dp"
    fresco:placeholderImage="@drawable/my_drawable"
    />

Step 6

Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/master/docs/static/logo.png");
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);

(-)
- Huge size of library
- No Callback with View, Bitmap parameters
- SimpleDraweeView doesn't support wrap_content
- Huge size of cache
(+)
- Pretty fast image loader (for small && medium images)
- A lot of functionality(streaming, drawing tools, memory management, etc)
- Possibility to setup directly in xml (for example round corners)
- GIF support
- WebP support


No comments:

Post a Comment