我想生成一个图像库,而不改变图像的纵横比。图像有不同的尺寸。我正在使用UICollectionView
和定位UIImageView
单元格内部。我使用下面的代码来获取图像大小。但它总是返回大小 0。
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
NSString* url = [selectedImages objectAtIndex:indexPath.row];
UIImageView *thumb;
ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *myError) {
NSLog(@"failed loading asset");
};
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myAsset) {
[thumb setImage:[UIImage imageWithCGImage:[myAsset aspectRatioThumbnail]]];
};
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
[lib assetForURL:[NSURL URLWithString:url] resultBlock:resultBlock failureBlock:failureBlock];
NSLog(@"%f,%f",thumb.image.size.height,thumb.image.size.width);
return thumb.image.size;
}