【发布时间】:2012-02-09 08:04:27
【问题描述】:
我正在编写一个应用程序,让用户可以拍摄照片并将它们分配给设备。为此,我需要能够存储拍摄图片的 URL,然后重新加载图片。
我知道对此进行过多次讨论,但奇怪的是,没有一个 Ansers 帮助我...
这是我保存图像的代码:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init];
UIImage * image;
// Request to save Image
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
image = [info objectForKey:UIImagePickerControllerEditedImage];
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL * assertURL, NSError * error){
if (error) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"PictureSaveErrorTitle", @"Title if saving picture fails")
message:NSLocalizedString(@"PictureSaveErrorMessage", @"Message if saving picture fails")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"PictureSaveErrorOK", @"OK if saving picture fails")
otherButtonTitles:nil];
[alert show];
} else {
[self setUserImage:[assertURL absoluteString]];
[imageOfDevice setImage:image];
}
}];
} else {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self setUserImage:[[info valueForKey:UIImagePickerControllerReferenceURL] path]];
}
[self dismissModalViewControllerAnimated:YES];
}
这是为了重新加载图像:
if (userImage != nil) {
ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init];
[library assetForURL:[NSURL fileURLWithPath:userImage]
resultBlock:^(ALAsset * asset){
[imageOfDevice setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
}
failureBlock:^(NSError * error){
NSLog(@"cannot get image - %@", [error localizedDescription]);
}];
}
有人看出有什么问题吗?
感谢您的帮助,
感应
【问题讨论】:
-
我仍在寻找有好主意的人来帮助我我仍然被这个愚蠢的问题所困扰。其实这不可能这么难。有很多应用程序在使用照片库,不是吗?
标签: ios image xcode4 camera alassetslibrary