我目前正在开展一个项目,我必须将图像保存到照片库,并为每个捕获的图像指定一个名称。我知道如何保存图像,但是如何为保存在库中的图像指定名称?
我的代码:
-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
imgglobal =imageView.image;
//for saving image in photo library
UIGraphicsBeginImageContext(self.imageView.bounds.size);
[self.imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
UIGraphicsEndImageContext();
UIImage *image1=imageView.image;
[self imageSavedToPhotosAlbum:image1 didFinishSavingWithError:nil contextInfo:nil];
}
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
NSString *message;
NSString *title;
if (!error) {
title = NSLocalizedString(@"SaveSuccessTitle", @"");
message = NSLocalizedString(@"SaveSuccessMessage", @"");
} else {
title = NSLocalizedString(@"SaveFailedTitle", @"");
message = [error description];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[alert show];
[alert release];
}
答案 0 :(得分:2)
照片库中的照片不包含任何名称。而且您也无法在照片库中创建文件夹。如果您确实需要照片的名称,请将其放在~/Documents
内并实施您自己的选择器。