iOS 尝试将图像保存到相机胶卷但未成功 [英] iOS attempting to save image to camera roll but not succeeding

查看:51
本文介绍了iOS 尝试将图像保存到相机胶卷但未成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIImageView 中有一张图片,想将其保存到设备的照片中,以便最终将其保存为墙纸.虽然代码编译没有错误,但图像不会保存,我担心在使用UIImage"与UIImageView"或其他东西时我做错了什么.图像的名称是Q115birdsfull~iphone.png",到目前为止我的代码如下.我做错了什么???

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. 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. The name of the image is "Q115birdsfull~iphone.png" and my code thus far is below. What am I doing wrong???

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 作为属性和一个 ivar.我没有在您的代码中看到的是您实际将该图像设置为任何内容的位置.这可能是您遗漏的步骤.

What you're attempting to save is a UIImage kept as a property and an 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.

尝试这样做:

- (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?");
    }
}

这篇关于iOS 尝试将图像保存到相机胶卷但未成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆