3 回答
TA贡献1785条经验 获得超8个赞
尽管Matthew Frederick的回答最受欢迎,并且长期以来一直是适当的回应,从iOS 5.0(苹果可用)开始dismissViewControllerAnimated:completion:,以取代现已弃用的(从iOS 6.0开始)dismissViewControllerAnimated:。
希望在完成块中执行图像信息字典检索应该对所有人都有意义。
从上面举个例子,现在看起来像:
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:^{
// Edited image works great (if you allowed editing)
myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND do whatever you want with it, (NSDictionary *)info is fine now
UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
}];
}
TA贡献1830条经验 获得超9个赞
我已经尝试了所有上述操作,但是在iPad 6.0 / 6.1模拟器上却没有运气,但是我发现信息包含“ UIImagePickerControllerReferenceURL”键,这是我的代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:NULL];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
if(NULL == image){
[MyImageLoader loadImageFromAssertByUrl:[info objectForKey:@"UIImagePickerControllerReferenceURL"]
completion:^(UIImage* img){
//img not null here
}];
}else{
//image not null here
}
}
而loadImageFromAssertByUrl的代码是:
+(void) loadImageFromAssertByUrl:(NSURL *)url completion:(void (^)(UIImage*)) completion{
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
UIImage* img = [UIImage imageWithData:data];
completion(img);
} failureBlock:^(NSError *err) {
NSLog(@"Error: %@",[err localizedDescription]);
}];
}
- 3 回答
- 0 关注
- 1605 浏览
添加回答
举报