UIImageWriteToSavedPhotosAlbum 仅保存 10 张图像中的 5 张。为什么?

发布于 2024-11-09 08:15:44 字数 624 浏览 0 评论 0原文

正如标题所示,我遇到了问题。 是否有任何限制,例如“每秒仅导出 3 个图像”或类似的限制?

        for (int frameStepper = 0; frameStepper < [Something frameCount]; frameStepper++)
        {
            //Get the filename.
            imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"frame_%i.jpg", frameStepper]];

            //Read image.
            UIImage *image = [[[UIImage alloc] initWithContentsOfFile:imagePath] autorelease];

            //Write image.
            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        }

执行此代码后,我导出了 10 张图像中的 5 张。看不出为什么。请帮忙,非常感谢。

I have the problem as the title goes.
Are there any restrictions, like "Export only 3 image per second", or something like?

        for (int frameStepper = 0; frameStepper < [Something frameCount]; frameStepper++)
        {
            //Get the filename.
            imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"frame_%i.jpg", frameStepper]];

            //Read image.
            UIImage *image = [[[UIImage alloc] initWithContentsOfFile:imagePath] autorelease];

            //Write image.
            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        }

I have 5 images exported out of 10 after this code. Cannot see why. Please help, many thanks.

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

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

发布评论

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

评论(2

等待圉鍢 2024-11-16 08:15:44

这个的一个变体帮助了我:
http://iphoneincubator.com/blog/tag/uiimagewritetosavedphotosalbum

{
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);

}


- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    if (error) {
        [self tryWriteAgain:image];
    }
}

-(void)tryWriteAgain:(UIImage *)image
{
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}

A variation of this helped me:
http://iphoneincubator.com/blog/tag/uiimagewritetosavedphotosalbum

{
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);

}


- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    if (error) {
        [self tryWriteAgain:image];
    }
}

-(void)tryWriteAgain:(UIImage *)image
{
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}
硪扪都還晓 2024-11-16 08:15:44

如果我记录完成错误,它会说:

Error Domain=ALAssetsLibraryErrorDomain Code=-3301 "Write busy" UserInfo=0x69e8e20 {NSLocalizedFailureReason=There was a problem writing this asset because the writing resources are busy., NSLocalizedRecoverySuggestion=Try to write again, NSLocalizedDescription=Write busy}

这意味着我必须通过实现给定的回调来等待正在运行的进程完成:

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

Hurray。

If I log the error of completion, it says:

Error Domain=ALAssetsLibraryErrorDomain Code=-3301 "Write busy" UserInfo=0x69e8e20 {NSLocalizedFailureReason=There was a problem writing this asset because the writing resources are busy., NSLocalizedRecoverySuggestion=Try to write again, NSLocalizedDescription=Write busy}

That means I have to wait for the completition of the running processes by implementing the given callback:

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

Hurray.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文