從 iphone 的 照片庫中選取的圖片窥妇,由于系統(tǒng)不能返回其文件的具體路徑征炼,所以要用到 ALAssetsLibrary 這個(gè)框架
首先導(dǎo)入框架 ALAssetsLibrary
導(dǎo)入頭文件 <ALAssetsLibrary/ALAssetsLibrary.h>
#pragma mark UIImagePickerController 的代理方法 進(jìn)行自定義控制器的操作-----
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{
__weak typeof(self) weakself = self;
[picker dismissViewControllerAnimated:YES completion:^{
UIImage *imageOriginal = [info objectForKey:UIImagePickerControllerOriginalImage];
ALAssetsLibrary* alLibrary = [[ALAssetsLibrary alloc] init];
[alLibrary assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSString *fileSize = [NSString stringWithFormat:@"(%@)",[weakself getFileSizeByBt:[NSNumber numberWithLongLong:representation.size]]];
NSLog(@"#################%@##################",fileSize);
} failureBlock:^(NSError *error) {
}];.h
//計(jì)算圖片大小
- (NSString *)getFileSizeByBt:(NSNumber *)fileSize{
CGFloat size = [fileSize floatValue];
if (size >= 1024*1024*1024) {
return [NSString stringWithFormat:@"%.2fG",size/(1024*1024*1024)];
}else if (size >= 1024*1024) {
return [NSString stringWithFormat:@"%.2fM",size/(1024*1024)];
}else{
return [NSString stringWithFormat:@"%.2fK",size/1024];
}
}