0

UIImageView に画像があり、デバイスの写真に保存して、最終的に壁紙として保存できるようにしたいと考えています。コードはエラーなしでコンパイルされますが、画像は保存されず、「UIImage」と「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);
}

よろしくお願いします!

4

1 に答える 1

3

保存しようとしているのはUIImage、プロパティと ivar として保持されています。コードに表示されないのは、実際にその画像を何かに設定する場所です。それはあなたが見逃しているステップかもしれません。

これを試してください:

- (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?");
    }
}
于 2012-06-23T05:06:05.373 に答える