如何快速将图像从摄像机保存到相册

问题描述:

我正在使用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]; 
} 

它抛出这样的错误:

写入繁忙, 有写这个资产,因为一个问题写资源很忙。

任何人都可以指出问题出在哪里?

+1

你下面的答案解决了你的问题吗? – Darren 2016-01-31 15:09:40

您需要检查完成块中的错误,如果它是ALAssetsLibraryWriteBusyError,那么您需要尝试再次保存该资产。这意味着当方法尝试写入磁盘时,其他人试图写入磁盘。