Get the picture's width and height according to the link of the picture

Source: Internet
Author: User

//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

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.