---
title: "ios 保存照片"
author: "bydshine"
date: "2013-05-07T15:39:24Z"
tags: []
categories: ["移动开发"]
slug: "ios"
draft: false
lastmod: "2013-05-07T15:39:24Z"
id: 1861113
url: "https://bydshine.iteye.com/blog/1861113"
---

保存已知图片：
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);