2
有没有一种简单的方法可以通过编程将视图保存到iPhone应用程序中的照片库?在iPhone应用程序中保存视图作为照片
有没有一种简单的方法可以通过编程将视图保存到iPhone应用程序中的照片库?在iPhone应用程序中保存视图作为照片
我将这些方法添加到我的视图的控制器类。他们保存照片,然后弹出一个警告框告诉用户它是否成功。
- (void)savePhotoOfView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size);
[view drawRect:view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),
NULL);
}
- (void) savedPhotoImage:(UIImage *)image
didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
NSString *message = @"This image has been saved to your Photos album";
if (error) {
message = [error localizedDescription];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
此代码保存白色图像(空白图像)进入我的照片明矾u能请指导我,我做什么错误,我有复制过去的,上面的代码到我的项目,但不工作:( – 2011-12-14 12:34:51