无法写入(添加 UIImage)到相册

发布于 2024-09-12 01:53:53 字数 477 浏览 2 评论 0原文

我有以下代码

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{

NSLog(@"failed");
}

来检查错误,并打印出我运行以下代码的时间:

-(IBAction) addWallpaper{

UIImageWriteToSavedPhotosAlbum( [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]]
                               , self, @selector(image:didFinishSavingWithError:contextInfo:), nil );
}

如何正确地将 UIImage 保存到相册?

I have the following code

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{

NSLog(@"failed");
}

which checks for the error, and it prints out time I run the following

-(IBAction) addWallpaper{

UIImageWriteToSavedPhotosAlbum( [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]]
                               , self, @selector(image:didFinishSavingWithError:contextInfo:), nil );
}

How do I correctly saved the UIImage to the photo album?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹 2024-09-19 01:53:53

尽管名称

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
                               contextInfo:(void *)contextInfo

并不表示错误。您需要检查传递给此函数的error

像这样的东西:

-(void)image:(UIImage *)image didFinishSavingWithError:(NSError*)error
                                  contextInfo:(void*)contextInfo
{
    UIAlertView *alert;
    if ( [error code] != 0 )
    {
            alert = [[UIAlertView alloc] initWithTitle:@"Sorry"
                       message:@"Things went wrong!"
                       delegate:nil
                       cancelButtonTitle:nil
                       otherButtonTitles:@"OK",nil];
    } else {
            alert = [[UIAlertView alloc] initWithTitle:@"Great"
                       message:@"Image was saved!"
                       delegate:nil
                       cancelButtonTitle:nil
                       otherButtonTitles:@"OK",nil];
    }
    [alert show];
    [alert release];
}

Despite the name

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
                               contextInfo:(void *)contextInfo

doesn't indicate an error. You need to check the error passed to this function.

Something like:

-(void)image:(UIImage *)image didFinishSavingWithError:(NSError*)error
                                  contextInfo:(void*)contextInfo
{
    UIAlertView *alert;
    if ( [error code] != 0 )
    {
            alert = [[UIAlertView alloc] initWithTitle:@"Sorry"
                       message:@"Things went wrong!"
                       delegate:nil
                       cancelButtonTitle:nil
                       otherButtonTitles:@"OK",nil];
    } else {
            alert = [[UIAlertView alloc] initWithTitle:@"Great"
                       message:@"Image was saved!"
                       delegate:nil
                       cancelButtonTitle:nil
                       otherButtonTitles:@"OK",nil];
    }
    [alert show];
    [alert release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文