照片, 功能, 保存
如何将指定的图片储存至系统的「照片」数据内,并检查储存动作是否成功
程序提供加载预设的图片并提供一组UIButton按钮
按下储存图片将检查此动作是否成功
SavedToPhotoAlbumViewController.h
1 #import <UIKit/UIKit.h> 2 3 @interface SavedToPhotoAlbumViewController : UIViewController { 4 IBOutlet UIImageView *myImageView; 5 } 6 7 @property (nonatomic,retain) UIImageView *myImageView; 8 9 -(IBAction) SaveImageToPhotoAlbum:(id)sender; 10 11 @end 12 13 SavedToPhotoAlbumViewController.m 14 15 16 @synthesize myImageView; 17 18 -(IBAction) SaveImageToPhotoAlbum:(id)sender{ 19 UIImageWriteToSavedPhotosAlbum(myImageView.image, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil); 20 } 21 22 - (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { 23 NSString *message; 24 NSString *title; 25 if (!error) { 26 title = NSLocalizedString(@"储存成功", @""); 27 message = NSLocalizedString(@"您的图片已正确的储存至照片数据", @""); 28 } else { 29 title = NSLocalizedString(@"储存失败", @""); 30 message = [error description]; 31 } 32 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:titlemessage:message delegate:nil 35 cancelButtonTitle:NSLocalizedString(@"好", @"") otherButtonTitles:nil]; 37 [alert show]; 38 [alert release]; 39 }