Objective c 通过AF2.0从URL获取一半大小的UIImage
我像下面一样在块期间确定下载图像的大小,然后我将相应地设置uiimageview的大小。 如何通过Afnetworking获取UIImage的实际大小,请帮助我 NSMutableURLRequest*request=[NSMutableUrlRequestWithURL:[NSURL URLWithString:str1]]Objective c 通过AF2.0从URL获取一半大小的UIImage,objective-c,iphone,afnetworking-2,Objective C,Iphone,Afnetworking 2,我像下面一样在块期间确定下载图像的大小,然后我将相应地设置uiimageview的大小。 如何通过Afnetworking获取UIImage的实际大小,请帮助我 NSMutableURLRequest*request=[NSMutableUrlRequestWithURL:[NSURL URLWithString:str1]] __weak UIImageView *weakImageView = cell.imageView; [cell.imageView setImageWithURL
__weak UIImageView *weakImageView = cell.imageView;
[cell.imageView setImageWithURLRequest:request
placeholderImage:[UIImage imageNamed:@"Plceholder-50X60.png"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
{
NSLog(@"image = %f, imageheight = %f", image.size.width, image.size.height);
UIImageView *strongImageView = weakImageView; //make local strong reference to protect against race conditions
if (!strongImageView) return;
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
NSLog(@"Request failed with error: %@", error);
}];
映像的大小取决于磁盘上映像文件的名称 如果文件名为Plceholder-50X60.png,则其实际大小为image.size with image.scale 1.0,但如果文件名为Plceholder-50X60@2x.png,它的实际大小将是CGSizeMakeimage.size.width*image.scale,image.size.height*image.scale和image.scale 2.0 技巧在ImageName:方法中,请参阅ImageName:的引用: 在运行iOS 4或更高版本的设备上,如果 设备屏幕的刻度为1.0。如果屏幕的刻度为2.0, 此方法首先搜索具有相同文件名的图像文件 附加了@2x后缀。例如,如果文件名为 按钮,它首先搜索button@2x. 如果它找到一个2x,它将加载 并设置返回的UIImage对象的缩放属性 到2.0。否则,它将加载未修改的文件名并设置比例 属性设置为1.0 结论:无论图像文件的名称是什么,都可以使用CGSizeMakeimage.size.width*image.scale、image.size.height*image.scale获得图像的实际大小