Android uses the open source framework fresco to process images

About the advantages of fresco, let's Google by ourselves. It's too powerful and excellent. I can't hold this small blog. Today, I'll give you a brief introduction to the use of fresco and some properties.

Fresco is a powerful image loading component. After using it, you don't need to care about the tedious things of loading and displaying pictures! Android 2.3 and later versions are supported.

The official website introduced some features of fresco in detail. I was really shocked when I saw it for the first time. https://www.fresco-cn.org/

2016 fresco's latest source code analysis: https://github.com/desmond1121/Fresco-Source-Analysis

Briefly describe the comparison with other common picture caching frameworks

(1) Volley provides a new control networkimageview to replace the traditional ImageView. If your project is a relatively small project or a project with low requirements, you can use this library for simple processing. This library is an open source library released by Google 2013 I / O. This library does not provide any image processing operations in image processing, so it can be used for fine-grained data connection.

(2) Universal image loader is an early image caching component, which has been highly praised by developers and used in many old applications.

(3) Picasso and glass, no doubt glass wins

(4) As a rookie, fresco is very prominent in terms of memory management (three-level cache), progressive presentation of images, loading of GIF images and webp format images. (also my favorite)

Introduction to common basic attributes involved

(1)layout_ Width and layout_ Height does not support warp_ Content, but you can use setaspectretio(); To set the aspect ratio

(2) Fadeduration() fade out time;

(3) Actualsimagescaletype is used to set the image zoom. Foucscrop is usually used. The attribute value will put the human head in the middle through the algorithm

(4) Placeholderimagescaletype of the image displayed before the download of the placeholderimage succeeded

(5) The image displayed when the failureimage fails to load. Failurelmagescatetype

(6) Retrylmage loading failed, prompting the user to click the reloaded picture retrylmage scatetype

(7) Progressbarimage indicates that the user is loading, which has nothing to do with the progress. Progressbarlmagescatetype

(8) Progressbarautorotateinterval the time interval at which pictures are automatically rotated

(9) Backgroundimage background

(10) Overlay image overlay

(11) Superimposed image when pressed

(12) Does roundascircle involve circles

(13) Roundedcornerradius fillet

(14) Roundtopleft, roundtopright... Set four corners with different radii respectively. After setting it to true, you can set the angles in the code through the setconnersradii() method of roundingparams.

(15) The overlay color of the roundwithoverlaycolor border

(16) Roundingborderwidth border width

(17) Roundingbordercolor border color

Let's briefly demonstrate the process of loading network pictures using fresco: the demonstration effect is as follows (you guessed right, it's my jade photo again):

Step 1: import dependent packages

Like the previous Android image indicator master project, Android studio 2.2 is still used this time. You can still add the following code directly under dependencies in build.gradle:

compile 'com.facebook.fresco:fresco:0.12.0'

At the same time, the following dependencies can be added according to individual project requirements:

Step 2: add network permissions

Because the network picture is loaded, you must add network permissions in the androidmanifest.xml configuration file:

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

Step 3: initialize fresco class

Before loading images, you must initialize the fresco class. You only need to call Fresco.initialize once to complete the initialization. Next, we introduce the initialization method in MainActivity and Application respectively.

(1) Call initialization in application (recommended)

After completing the above work, you need to specify the application class in androidmanifest.xml.

(2) initialization in MainActivity.

It should be noted that it should be initialized before setcontentview

Step 4: XML layout file in layout

Before layout, you need to add a namespace to the XML file

xmlns:fresco=" http://schemas.android.com/apk/res-auto "

The specific layout files are as follows. In this demonstration, click the start image to load and use simpledraweeview (Note: layout_width / height does not support wrap_content):

Step 5: Java implementation code

For the rest, fresco will complete it for you, for example: display the occupied bitmap until loading is completed; Download pictures; Cache pictures; When the picture is no longer displayed, remove it from memory, etc.

This article only introduces the most basic usage of fresco. Big guys can visit the official website to try other functions.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>