iOS picture loading Framework Learning Flyimage

Source: Internet
Author: User
Tags file copy webp uikit

On iOSDevelopment, its picture loads the new frame flyimageintegrates theSdwebimage,Fastimagecache,afnetworkingthe advantages of a new performance-efficient, easy-to-interface picture loading framework, the following small series and everyone together to grilled this frame. featuresEfficientcan be more than one small map decoding and storage on the same large map, in the same screen rendering multi-graph, high efficiency;SupportMmapmemory-mapped, efficientI/Ooperation, reduce the file copy operation, and reduce the memory consumption at the same time;SupportByte Alignmentbyte on it, during rendering, avoid executingCa::render::copy_imagememory operation;Simple InterfaceSupportUiimageview, Calayer Category;Do not consider the small image size, simple storage and reading interface;the scheme solves two kinds of business scenarios of single large image and multiple small graphs simultaneously.WebPefficient image compression method;Asynchronous Download support download ProgressBlock, to facilitate the implementation of customized download animation;Popular Frame comparisonnowIoson the more popular two sets of picture loading frames:Sdwebimageprovides a complete set of solutions from download to rendering, while supportingCategoryfeatures,WebPformat, it is very simple to use, but the same screen multiple small graphs quickly scrolling, the interface will be very obvious lag;Fastimagecache Pathis ideal for efficient rendering of small images, and the interior is optimized forI/Oread, decode supportByte Alignmentreduced memory copy, while only one decoding, can be said to be extremely optimized. ButFICThere are two major drawbacks:to streamline the code, from1.2later cancel the image download function;interface is very difficult to use, you also need to specifyFicimageformat, eachFormatthe pictures insizemust maintain aat the same time each picture needs to be[Ficentitybinding, I just want to quickly show multipleicononly...based on the above analysis, if there is a picture library can combine the advantages of the two together, then how good! Flyimagebased on this idea, the new library integratesFastimagecacheoptimization Scheme while making the interface easier to use. Flyimageyou can draw multiple different images in one file.sizethe small picture, stored and retrieved only requires a fixedKeyat the same time, the method of memory mapping is applied to the display scheme of large picture, which reduces the number of copies of memory and speeds up the reading speed. Here's how to use it:How to useinstallationPlatform:ios, ' 8.0 ' pod ' flyimage ' ~>1.0 'UseUiimageview/calayeruiimageview *iconview = [[Uiimageview alloc] initWithFrame:]; [IconView seticonurl:[nsurl urlwithstring:@ "http://original"]; []self.view Addsubview:iconview];Useflyimagecache//throughKeyget a single picture[[Flyimagecache Sharedinstance] asyncgetimagewithkey:keycompleted:^ (nsstring *key, UIImage *image) {imageview.image = image;}];/ /Delete a picture[[Flyimagecache Sharedinstance] removeimagewithkey:key];//Clear All Pictures[[Flyimagecache sharedinstance] purge];Useflyimageiconcache//Add a small picture[[Flyimageiconcache sharedinstance] Addimagewithkey:keysize:drawsizedrawingblock:^ (cgcontextref context, CGRect contextbounds) {//Draw ManuallyUIImage *image = [UIImage imagewithname:@ "ImageName"]; Uigraphicspushcontext (context); [Image Drawinrect:contextbounds]; Uigraphicspopcontext ();} completed:nil];//get a small picture[[Flyimagecache Sharedinstance] asyncgetimagewithkey:keycompleted:^ (nsstring *key, UIImage *image) {imageview.image = image;}];PerformanceMemoryTest Engineering: Flyimageview/device:iphone6 Plus, scroll through the list to display a large number of images consecutively,Flyimagedoes not increaseImage IOof Memory
Memory Flyimage Sdwebimage UIKit
All HEAP Allocations 2~7m 2~4m 2~5m
All Anonymous VMS 17~30m 310M 17~30m
FpsTest Engineering: Flyimageiconview/device:iphone6 Plus, same-screen rendering thea small picture,Flyimagea smooth browsing experience
Flyimage Sdwebimage UIKit
58~60fps 6~7fps 6~7fps

Multi-image on the same screenclass DiagramFlyimagedatafileencapsulates themmapoperation, providing efficientI/Ofile operation, supports the function of reading, writing and dynamically expanding file length. Flyimagedatafilemanagerresponsible forFlyimagedatafileadditions, deletions, and lookups. Users cannot instantiate directlyFlyimagedatafile, but need to passManagerdo this, and you can get the number of files and the amount of space under the current folder. Flyimagedecoderdecodes the memory data and generatesUIImageobject. WebPThe conversion of the format is done in that class. Flyimageencoderto beFlyimageiconcacheclass service, drawing the picture onto the canvas, creatingBitmapformat. Flyimagecacheresponsible for image additions, deletions, and lookups. Each picture corresponds to aKey, this information will be stored in a file. When the class is instantiated, it automatically creates or automatically gets the file, you can specify a different The file path. In the actual use of the process,Appwill provide the action to clear the current cache, but also want to keep some necessary pictures, such as the current user's avatar and unpublished draft pictures, for this demand,Flyimagecacheprovides a convenient interface-(void) Protectfilewithkey: (nsstring*) key; and the-(void) Unprotectfilewithkey: (nsstring*) key; operation, inProtectpicture of the state even in the executionPurgeoperation is not cleared. Flyimageiconcacheresponsible for adding, deleting, replacing, and finding small images. and theFlyimagecacheinterface is basically the same, except that the class maintains only oneFlyimagedatafileexample, all small images will be stored in the file after decoding. Of course you can also create multiple instances and place small images that you often use together in aFlyimagedatafilethe. Flyimagedownloaderbe responsible for downloading pictures, note that this class is not responsible for storage. After initiating a download request, you will get a type ofFlyimagedownloadhandlerididentifier that can be called if the picture is moved out of the current display area-(void) Canceldownloadhandler: (flyimagedownloadhandlerid*) Handlerid; Remove the download request and save resources. Uiimageview+flyimagecache, Calayer+flyimagecacheto beUiimageviewprovides a convenient classification interface`. -(void) Setimageurl: (nsurl*) URL; Uiimageview+flyimageiconcache, Calayer+flyimageiconcacheto beCalayerprovides a convenient classification interface`. -(void) Seticonurl: (nsurl*) URL;Article Source:Cocoachina

iOS picture loading Framework Learning Flyimage

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.