Android Web image loading artifact fresco

Source: Internet
Author: User

Fresco is Facebook's newest, powerful image library for displaying images in Android apps that can load images from the Web, local storage, and local resources. The drawees can display placeholders until the picture is loaded. When the picture disappears from the screen, the memory is automatically freed.

Fresco is a powerful image loading library on Facebook's open source Android platform and the most powerful image loading library on the Android platform to date.

Fresco is a powerful picture loading component. After using it, you do not need to care about the loading of pictures and show these tedious things! Supports Android 2.3 and later versions.

Fresco Source: Https://github.com/facebook/fresco

Fresco Official document (Chinese): https://www.fresco-cn.org/

Fresco source Online View: http://frescolib.org/javadoc/reference/packages.html

Currently the latest version is: Fresco 1.1.0

Gradle Introduction (Of course you can also introduce a high version)

   compile ‘com.facebook.fresco:fresco:0.12.0‘// 支持 GIF 动图,需要添加 compile ‘com.facebook.fresco:animated-gif:0.12.0‘

Run: (Note: This case only completed the corresponding function in the diagram, fresco more functions to the official view, explain the details)

      

Characteristics

1: Memory Management

The extracted images, which are bitmap in Android, occupy a lot of memory. Large memory usage is bound to cause more frequent GC. Under 5.0, the GC will significantly cause the interface to stutter.

In the system below 5.0, Fresco puts the picture in a special memory area. Of course, when the picture is not displayed, the memory that is occupied is automatically released. This will make the app smoother and reduce the oom caused by image memory usage.

Fresco is performing as well on low-end machines, and you no longer have to after thinking the memory footprint of your images.

2: Picture loading

Fresco's image Pipeline allows you to customize the image loading process in a number of ways, such as:

    • Specify a different remote path for the same picture, or use a picture that already exists in the local cache
    • Show a low-resolution image first, and then display high-definition image after download
    • Load completion callback Notification
    • For this map, if you have an EXIF thumbnail, you can display the thumbnail before the large map loading is complete.
    • Zoom or rotate a picture
    • Re-process the downloaded picture
    • Support WEBP decoding, even in the previous WEBP support for the imperfect Android system can also be used properly!

3: Picture Drawing

Fresco's drawees design brings some useful features:

    • Customize Center Focus
    • Fillet chart, of course the circle is OK
    • After the download fails, click reproduce download
    • Custom placeholder bitmap, custom overlay, or progress bar
    • Specify the overlay when the user presses

4: Progressive rendering of images

Progressive JPEG image format has been popular for several years, progressive picture format first presents a rough outline of the picture, and then as the picture continues to download, showing a gradually clear picture, which for mobile devices, especially slow network has great positive, can bring a better user experience.

The image Library of Android itself does not support this format, but fresco supports it. When used, as always, just need to provide a picture of the URI can, the rest of the matter, Fresco will handle

5: Dynamic Graph loading

Loading gifs and WEBP is a very frustrating thing for any Android developer to look at. Each frame is a big one Bitmap , and each animation has a lot of frames. Fresco makes you without these worries, it handles every frame and manages your memory.

Code: (Attributes can be set as required note:android:layout_height= "200DP" property value cannot be: wrap_content)

 <!--Fresco:actualimagescaletype: The scaled style of the actual loaded picture fresco:backgroundimage: Underlying image resource fresco:fadeduration: progress bar and placeholder picture gradually Vanishing, loaded picture gradually shows the time interval fresco:failureimage: Picture resource displayed when load fails Fresco:failureimagescaletype: Stretched style of picture loaded when loading failed FRESC O:overlayimage: A picture that overlays a picture on the surface of the displayed image resource fresco:placeholderimage: Placeholder picture resource fresco:placeholderimagescaletype: scaling of placeholder pictures Style Fresco:progressbarautorotateinterval: progress bar Picture rotation period Fresco:progressbarimage: progress bar Picture Resource Fresco:progressbari Magescaletype: The stretch style of the progress bar picture fresco:retryimage: The picture resource that prompts reload Fresco:retryimagescaletype: The stretch style of the picture that prompts reload Fres Co:roundascircle: Cut the picture into circular fresco:viewaspectratio: Picture aspect ratio -    <com. Facebook.drawee.view.SimpleDraweeView Android:id= "@+id/id_main_sdv_sdv"Android:layout_width= "Match_parent"Android:layout_height= "200DP"Fresco:actualimagescaletype= "Focuscrop"fresco:fadeduration= " the"Fresco:failureimage= "@mipmap/ic_launcher"Fresco:failureimagescaletype= "Centerinside"Fresco:placeholderimage= "@mipmap/ic_launcher"Fresco:placeholderimagescaletype= "Fitcenter"Fresco:progressbarautorotateinterval= "+"Fresco:progressbarimage= "@drawable/aa"Fresco:progressbarimagescaletype= "Centerinside"Fresco:retryimage= "@mipmap/ic_launcher"Fresco:retryimagescaletype= "Centercrop"fresco:roundascircle= "false"Fresco:viewaspectratio= "1.6" />

Load Mode 1:

  simpledraweeview SDV = (simpledraweeview) Findviewbyid (R.ID.ID_MAIN_SDV_SDV);  Uri  Uri. Parse ("http://image5.tuku.cn/pic/wallpaper/fengjing/menghuandaziranmeijingbizhi/009.jpg");  Sdv.setimageuri (URI);

Load Mode 2:

 SimpleDraweeView sdv2 = (SimpleDraweeView) findViewById(R.id.id_main_sdv_sdv2); sdv2.setImageURI("http://img.my.csdn.net/uploads/201407/26/1406383243_5120.jpg");

Load Mode 3:

 SimpleDraweeView1 = (Simpledraweeview) Findviewbyid ( R.id.user_avator); Simpledraweeview1.setcontroller (Fresco.newdraweecontrollerbuilder (). Setimagerequest (Ima Gerequestbuilder.newbuilderwithsource (Uri.parse ( "htt P://avatar.csdn.net/8/6/0/1_dickyqie.jpg ")). Setprogressiverenderingenabled (true). Build ()). Setoldcontroller (Simpledraweeview1.getcontrolle R ()). build ());      
Load mode gif Picture:
 Uri uri = Uri.parse("http://ww1.sinaimg.cn/mw600/6345d84ejw1dvxp9dioykg.gif");        simpleDraweeView2 = (SimpleDraweeView) findViewById(R.id.user_avator2);        DraweeController draweeController1 = Fresco.newDraweeControllerBuilder().setUri(uri).setAutoPlayAnimations(true).build();        simpleDraweeView2.setController(draweeController1);        simpleDraweeView2.setOnTouchListener(this);

代码设置属性:

 The code sets the properties of the Simpledraweeview (overrides all the attributes of the XML setting, that is, properties that are not in the XML will be invalidated)Note: A genericdraweehierarchy is not allowed to be shared by multiple Simpledraweeview simpledraweeview SDV = (simpledraweeview) Findviewbyid (         R.ID.ID_MAIN_SDV_SDV); Genericdraweehierarchy hierarchy =New Genericdraweehierarchybuilder (Getresources ()). Setfadeduration ( 3000). Setplaceholderimage (R.mipmap.ic_launcher). Setplaceholderimagescaletype (ScalingUtils.ScaleType.FIT_XY). Setprogressbarimage (< Span class= "Hljs-keyword" >new progressbardrawable ()) // Displays the progress bar (the fresco's own progress bar). Build (); //set picture fillet roundingparams roundingparams = new roundingparams (); Roundingparams.setroundascircle (false); //do not cut the picture into round Roundingparams.setcornersradius (200); Hierarchy.setroundingparams (Roundingparams); Sdv.sethierarchy (hierarchy);              
 
SOURCE Click to download
 

Android Web image loading artifact fresco

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.