已知图片保存到相册
UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:photoName], self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
if (error == nil)
{
alert = [[UIAlertView alloc] initWithTitle:nil message:@"This picture has been saved to your photo album.Picture Saved!" delegate:nilcancelButtonTitle:@"OK." otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
alert = [[UIAlertView alloc] initWithTitle:nil message:@"Please try it again later.Saving Failed" delegate:nilcancelButtonTitle:@"OK." otherButtonTitles:nil];
[alert show];
[alert release];
}
}
保存当前视图:
#import <QuartzCore/QuartzCore.h>
UIGraphicsBeginImageContext(currentView.bounds.size); //currentView当前的view
[currentView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
本文介绍如何在iOS应用中使用Objective-C保存UIImage到用户的相册,并提供了保存当前视图区域为图片的方法。通过调用UIImageWriteToSavedPhotosAlbum函数实现图片保存,并附带了错误提示处理。
2166

被折叠的 条评论
为什么被折叠?



