Why Sdwebimage loading pictures without card?

Source: Internet
Author: User

Before we do the image asynchronous loading often encountered in the sliding tableview when the situation, but we do download and create UIImage objects in the sub-thread and then in the main thread to do the reality, and with Sdwebimage when the card is not, In fact, it is easy to find out what the code is:

#import "SDWebImageDecoder.h"@implementationUIImage (Forcedecode)+ (UIImage *) Decodedimagewithimage: (UIImage *) Image {if(image.images) {//Do not decode animated images        returnimage; } cgimageref imageref=image.    Cgimage; Cgsize imageSize=Cgsizemake (Cgimagegetwidth (Imageref), Cgimagegetheight (Imageref)); CGRect Imagerect= (CGRect) {. origin = Cgpointzero,. Size =ImageSize}; Cgcolorspaceref ColorSpace=Cgcolorspacecreatedevicergb (); Cgbitmapinfo Bitmapinfo=Cgimagegetbitmapinfo (IMAGEREF); intInfomask = (Bitmapinfo &kcgbitmapalphainfomask); BOOL Anynonalpha= (Infomask = = Kcgimagealphanone | |Infomask= = Kcgimagealphanoneskipfirst | |Infomask==kcgimagealphanoneskiplast); //Cgbitmapcontextcreate doesn ' t support Kcgimagealphanone with RGB. // https://developer.apple.com/library/mac/#qa/qa1037/_index.html    if(Infomask = = Kcgimagealphanone && cgcolorspacegetnumberofcomponents (colorspace) >1) {        //Unset the old alpha info.Bitmapinfo &= ~Kcgbitmapalphainfomask; //Set Noneskipfirst.Bitmapinfo |=Kcgimagealphanoneskipfirst; }            //Some PNGs Tell us they has alpha but only 3 components. Odd.    Else if(!anynonalpha && cgcolorspacegetnumberofcomponents (colorspace) = =3) {        //Unset the old alpha info.Bitmapinfo &= ~Kcgbitmapalphainfomask; Bitmapinfo|=Kcgimagealphapremultipliedfirst; }    //It calculates the bytes-per-row based on the bitspercomponent and width arguments.Cgcontextref context =cgbitmapcontextcreate (NULL, ImageSize.Width, Imagesize.height, Cgimagegetbitspercomp Onent (imageref),0, ColorSpace, bitmapinfo);    Cgcolorspacerelease (ColorSpace); //If failed, return undecompressed image    if(!context)returnimage;    Cgcontextdrawimage (context, imagerect, imageref); Cgimageref Decompressedimageref=cgbitmapcontextcreateimage (context);    Cgcontextrelease (context); UIImage*decompressedimage =[UIImage imagewithcgimage:decompressedimageref Scale:image.scale orientation:image.imageOrientation];    Cgimagerelease (DECOMPRESSEDIMAGEREF); returndecompressedimage;}@end

In the sub-thread, the SD has acquired the UIImage object, but he did not directly display the picture, but did the following operations, to obtain a new UIImage object, in fact, the process is to understand the image data pressure, if not to do so, This process will be performed in the main thread at the time of the actual image. So ...

Why Sdwebimage loading pictures without card?

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.