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?