标题出现时我遇到了问题。 是否有任何限制,例如“每秒仅导出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张图片从10张中导出。看不出原因。请多多帮助,谢谢。
答案 0 :(得分:3)
这种变化帮助了我: 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);
}
答案 1 :(得分:2)
如果我记录完成错误,它会说:
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
乌拉。