The defect and solution of sdwebimage loaded GIF motion diagram

Source: Internet
Author: User

Sdwebimage set cache management, asynchronous download, download times control and optimization functions in one, is basically the iOS developed a standard component. However, in the actual development process, it is found that the support of Sdwebimage to animated GIF is not satisfactory. sample pictures are as follows:

Using Sdwebimage to load the display is much slower than the actual effect
cause Analysis

In Sdwebimage's core file there is a gif extension of uiimage, in which the program gets the image of each frame of GIF and the corresponding display time

for (size_t i = 0; i < count; i++) {
            //Get GIF each frame image
            cgimageref images = cgimagesourcecreateimageatindex (source, I, NULL);
            if (!image) {
                continue;
            }
            Sd_framedurationatindex Gets the display time of each frame image
            duration + = [self sd_framedurationatindex:i source:source];

            [Images addobject:[uiimage imagewithcgimage:image scale:[uiscreen mainscreen].scale Orientation: Uiimageorientationup]];

            Cgimagerelease (image);
        }

        if (!duration) {
            duration = (1.0f/10.0f) * count;
        }
        Create a dynamic diagram
        animatedimage = [UIImage animatedimagewithimages:images duration:duration];

The problem is that when the author obtains the display time of each frame, the purpose is only to compute the total time length of the GIF animation, and does not assign the corresponding weights to the display time of each frame, which results in the average time of each frame image, and brings the cotton effect solution to the person visually.

The solution is actually very simple, because the method provided by the system

+ (UIImage *) Animatedimagewithimages: (nsarray<uiimage *> *) images Duration: (nstimeinterval) duration

Will split the duration into each frame image, in order to achieve the effect of weight distribution, you can increase the number of frames that display time long pictures

There's a mayoff/uiimage-from-animated-gif on the GitHub, that's the principle.
We replace the Sd_animatedgifwithdata method of the Sdwebimage uiimage+gif.m file with the new method

Lazy classmate point here to download the replacement of good files uiimage+gif.m
If you put aside the reliance on sdwebimage, there are other GIF display methods, no longer one by one repeat

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.