首页 > 代码库 > 根据图片的链接获取图片的宽高
根据图片的链接获取图片的宽高
//根据图片的链接获取图片的宽高- (CGSize)downloadImageSizeWithURL:(id)imageURL{ NSURL *URL = nil; if([imageURL isKindOfClass:[NSURL class]]){ URL = imageURL; } if([imageURL isKindOfClass:[NSString class]]){ URL = [NSURL URLWithString:imageURL]; } if(URL == nil) return CGSizeZero; #ifdef dispatch_main_sync_safe if([[SDImageCache sharedImageCache] diskImageExistsWithKey:absoluteString]){ UIImage* image = [[SDImageCache sharedImageCache] imageFromMemoryCacheForKey:absoluteString]; if(!image){ NSData* data =http://www.mamicode.com/ [[SDImageCache sharedImageCache] performSelector:@selector(diskImageDataBySearchingAllPathsForKey:) withObject:URL.absoluteString]; image = [UIImage imageWithData:data]; } if(image){ return image.size; } }#endif CGSize 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 =http://www.mamicode.com/ [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:URL] returningResponse:nil error:nil]; UIImage* image = [UIImage imageWithData:data]; if(image){#ifdef dispatch_main_sync_safe [[SDImageCache sharedImageCache] storeImage:image recalculateFromImage:YES imageData:data forKey:URL.absoluteString toDisk:YES];#endif size = image.size; } } return size;}
原帖地址:http://blog.csdn.net/li6185377/article/details/26225799
根据图片的链接获取图片的宽高
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。