[英]iOS attempting to save image to camera roll but not succeeding
I have an image in an UIImageView and want to save it to the device's photos so that it can be ultimately saved as a wallpaper. 我在UIImageView中有一个图像,并希望将其保存到设备的照片中,以便最终可以将其另存为墙纸。 Although the code compiles without an error the image does not save and I fear that I am doing something wrong when it comes to using 'UIImage' vs 'UIImageView' or something else all together. 尽管代码编译没有错误,但是图像并没有保存,我担心在使用'UIImage'vs'UIImageView'或其他所有东西时我做错了什么。 The name of the image is "Q115birdsfull~iphone.png" and my code thus far is below. 图像的名称是“ Q115birdsfull〜iphone.png”,到目前为止,我的代码在下面。 What am I doing wrong??? 我究竟做错了什么???
Q115birdsViewController.h Q115birdsViewController.h
#import <UIKit/UIKit.h>
@interface Q115birdsViewController : UIViewController
{
UIImage *Q115birdsfull;
}
@property (nonatomic, strong) UIImage *Q115birdsfull;
- (IBAction)onClickSavePhoto:(id)sender;
@end
Q115birdsViewController.m 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);
}
` Thank you in advance! `预先谢谢!
What you're attempting to save is a UIImage
kept as a property and an ivar. 您要保存的是将UIImage
保留为属性和ivar。 What I don't see in your code is where you actually set that image to anything. 我不在你的代码看到的是,你实际上是图像设置为任何东西。 That may be the step you are missing. 那可能就是您所缺少的步骤。
Try doing this: 尝试这样做:
- (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?");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.