保存并加载图像

时间:2014-04-28 17:19:32

标签: ios objective-c nsdata

我将创建一个撤消按钮,它会重置原始图片(加载保存的图像)。 但是,如果按下撤消按钮,则会隐藏整个图像视图。

我希望有人可以帮助我。

这是我的代码:

    - (IBAction)undo:(id)sender
{
    NSString *cachedFolderPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    NSString *cachedImagePath = [cachedFolderPath stringByAppendingPathComponent:@"image.png"];
    UIImage *image1 = [UIImage imageWithData:[NSData dataWithContentsOfFile:cachedImagePath]];
    [self->imgView setImage:image1];
}


- (void)saveImage: (UIImage*)image
    {
    UIImage *image1 = imgView.image;
    NSString *cachedFolderPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    NSString *cachedImagePath = [cachedFolderPath stringByAppendingPathComponent:@"image.png"];
    [UIImagePNGRepresentation(image1) writeToFile:cachedImagePath atomically:YES];
    }

调试:

首先(UIImage(image1)不是)

enter image description here

第二个(UIImage(image1)是零,但我不知道为什么):

enter image description here

0 个答案:

没有答案
相关问题