2011-06-15 139 views
2

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

回答

1

您需要檢查完成塊中的錯誤,如果它是ALAssetsLibraryWriteBusyError,那麼您需要嘗試再次保存該資產。這意味着當方法嘗試寫入磁盤時,其他人試圖寫入磁盤。

相關問題