加载保存的图像

时间:2014-04-27 13:38:58

标签: ios objective-c nsdata

我开发了一个应用程序,我可以在其中应用查找过滤器。现在我想创建一个撤销按钮,它将重置原始图像,该图像是在imageView中加载图像后保存的。我有这段代码:

- (IBAction)undo:(id)sender
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString* path = [documentsDirectory stringByAppendingPathComponent:
                      @"test.png" ];
    UIImage* image = [UIImage imageWithContentsOfFile:path];
    [self->imgView setImage:image];
}




- (void)saveImage: (UIImage*)image
{
    if (image != nil)
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString* path = [documentsDirectory stringByAppendingPathComponent:
                          @"test.png" ];
        NSData* data = UIImagePNGRepresentation(image);
        [data writeToFile:path atomically:YES];
    }
}

但是当我按下撤销按钮时,imageView将被关闭。

我希望有人可以帮助我。

1 个答案:

答案 0 :(得分:0)

尝试使用

[self.imgView setImage:image];

而不是

[self->imgView setImage:image];