获取ios相册图片文件大小,
很多人,想到的就是取到文件图片的位置,然后通过NSdata来获取图片大小,殊不知,这样获取到的图片大小并非准确。
正确的方法应是在代理中实现
ALAssetsLibrary* alLibrary = [[ALAssetsLibrary alloc] init];
[alLibrary assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset)
{
ALAssetRepresentation *representation = [asset defaultRepresentation];
if ([representation size] > 1024*1024*2) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"图片超出了2M,请重新选择" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
[alert release];
[self setretakeButtonEnable:picker];
[alLibrary release];
return;
}
}
时间: 2024-10-07 15:04:02