//get the picture's width and height according to the link of the picture-(Cgsize) Downloadimagesizewithurl: (ID) imageurl{Nsurl*url =Nil; if([ImageURL Iskindofclass:[nsurlclass]]) {URL=ImageURL; } if([ImageURL iskindofclass:[nsstringclass]]) {URL=[Nsurl Urlwithstring:imageurl]; } if(URL = =Nil)returnCgsizezero;#ifdefDispatch_main_sync_safeif([[[Sdimagecache Sharedimagecache] diskimageexistswithkey:absolutestring]) {UIImage* Image =[[Sdimagecache Sharedimagecache] imagefrommemorycacheforkey:absolutestring]; if(!image) {NSData* data =[[Sdimagecache Sharedimagecache] Performselector: @selector (diskimagedatabysearchingallpathsforkey:) WithObject:URL.absoluteString]; Image=[UIImage Imagewithdata:data]; } if(image) {returnimage.size; } }#endifcgsize Size=Cgsizezero; Nsmutableurlrequest*request =[[Nsmutableurlrequest alloc] initwithurl:url]; NSString*pathextendsion =[Url.pathextension lowercasestring]; if([Pathextendsion isequaltostring:@"PNG"]) {size=[self downloadpngimagesizewithrequest:request]; }Else if([Pathextendsion isequal:@"gif"]) {size=[self downloadgifimagesizewithrequest:request]; }Else{size=[self downloadjpgimagesizewithrequest:request]; } if(Cgsizeequaltosize (Cgsizezero, size)) {NSData* data =[nsurlconnection sendsynchronousrequest:[nsurlrequest Requestwithurl:url] Returningresponse:nil Error:nil]; UIImage* Image =[UIImage Imagewithdata:data]; if(image) {#ifdefDispatch_main_sync_safe [[Sdimagecache Sharedimagecache] Storeimage:image recalculatefromimage:yes imageDa Ta:data forKey:URL.absoluteString Todisk:yes];#endifsize=image.size; } } returnsize;}
Original address:http://blog.csdn.net/li6185377/article/details/26225799
Get the picture's width and height according to the link of the picture