iOS试图将图像保存到相机胶卷,但没有成功

我有一个UIImageView中的图像,并希望将其保存到设备的照片,以便它可以最终保存为壁纸。 虽然代码编译没有错误的图像不保存,我担心,当涉及到使用“UIImage”vs“UIImageView”或其他所有的东西,我做错了什么。 图像的名称是“Q115birdsfull〜iphone.png”,我的代码到目前为止是在下面。 我究竟做错了什么???

Q115birdsViewController.h

#import <UIKit/UIKit.h> @interface Q115birdsViewController : UIViewController { UIImage *Q115birdsfull; } @property (nonatomic, strong) UIImage *Q115birdsfull; - (IBAction)onClickSavePhoto:(id)sender; @end 

Q115birdsViewController.m

 #import "Q115birdsViewController.h" @interface Q115birdsViewController () @end @implementation Q115birdsViewController @synthesize Q115birdsfull; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (IBAction)onClickSavePhoto:(id)sender{ UIImageWriteToSavedPhotosAlbum(Q115birdsfull, nil, nil, nil); } 

`提前谢谢!

你试图保存的是一个UIImage作为一个财产和一个伊娃。 在你的代码中没有看到的是你真正把这个图像设置为任何东西的地方。 这可能是你错过的一步。

尝试这样做:

 - (IBAction)onClickSavePhoto:(id)sender{ if(Q115birdsfull == NULL) { NSLog( @"there is no Q115birdsfull image set"); Q115birdsfull = [UIImage imageNamed: @"Q115birdsfull"]; // if it's STILL null, we'll try a much more specific name if(Q115birdsfull == NULL) { Q115birdsfull = [UIImage imageNamed: @"Q115birdsfull~iphone"]; } } if(Q115birdsfull){ // by the way, variable names should *always* start with lower case letters UIImageWriteToSavedPhotosAlbum(Q115birdsfull, nil, nil, nil); } else { NSLog( @"never found the Q115birdsfull png file... is it really being copied into your built app?"); } }