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.
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);
}
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.
精彩评论