Iphone UIImageWriteToSavedPhotosAlbum只保存10个图像中的5个。为什么?
我有一个标题上的问题。 是否有任何限制,例如每秒仅导出3个图像,或者类似的限制Iphone UIImageWriteToSavedPhotosAlbum只保存10个图像中的5个。为什么?,iphone,uiimage,export,Iphone,Uiimage,Export,我有一个标题上的问题。 是否有任何限制,例如每秒仅导出3个图像,或者类似的限制 for (int frameStepper = 0; frameStepper < [Something frameCount]; frameStepper++) { //Get the filename. imagePath = [documentsDirectory stringByAppendingPathComponent:
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);
}
我有5个图像导出后,这10个代码。我不明白为什么。请帮助,非常感谢。如果我记录完成错误,它会显示:
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
万岁。这方面的一个变化帮助了我:
测试图像是否不为null,可能图像不在提供的路径上。示例:它们是。所以没有任何限制?
{
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);
}