ios 判断相册文件图片大小的方法

时间:2015-01-12 15:54:05   收藏:0   阅读:1342

获取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;

         }

}

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!