如何快速将相机拍摄的图像保存到相册
我正在使用 AVFoundation 来实现 captureStillImage 功能。
当我使用以下代码将图像写入 iphone 上的相册时,
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
UIImage *image = [[UIImage alloc] initWithData:imageData];
NSLog(@"capturestill image size is %@", NSStringFromCGSize(image.size));
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:completionBlock];
[image release];
[library release];
}
它会抛出如下错误:
Write Busy, 由于写入资源繁忙,写入此资产时出现问题。
任何人都可以指出问题出在哪里?
I am using AVFoundation to implement captureStillImage function.
When I use the follow code to write an Image to album on iphone ,
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
UIImage *image = [[UIImage alloc] initWithData:imageData];
NSLog(@"capturestill image size is %@", NSStringFromCGSize(image.size));
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:completionBlock];
[image release];
[library release];
}
it throw an error like this:
Write Busy,
There was a problem writing this asset because the writing resources are busy.
Any one can point out where is the problem?
您需要检查完成块中的错误,如果是 ALAssetsLibraryWriteBusyError,则需要再次尝试保存该资源。这意味着当该方法尝试写入磁盘时,其他东西正在尝试写入磁盘。
You need to check the error in the completion block and if it is ALAssetsLibraryWriteBusyError, then you need to try to save that asset again. It means something else was trying to write to disk when the method attempted to write to disk.