我正在开发一个包含一些标准“相机”功能的 iPhone 应用程序。保存到相机胶卷真的太慢了,在 iPhone 4 上大约需要四秒钟。有什么方法可以提高速度吗?
如果您查看默认的 iPhone 相机应用程序,它可以毫无延迟地拍摄后续照片,并且照片会立即保存到磁盘(如果您单击最后一张照片的小方块,在屏幕的下角,照片库总是在保存的照片上打开,即使你拍了很多照片)。
这是我用来从缓冲区获取图像然后将照片保存在相机胶卷中的重要代码的两个片段;我尝试在第二个片段之前和之后放置一个 NSLog,它确认了 4 秒的延迟来完成保存过程。
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
...
ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
NSLog(@"SCATTO: Inizio salvataggio in library...");
[library writeImageToSavedPhotosAlbum:[image CGImage] metadata:exifAttachments_dictionary completionBlock:^(NSURL *newURL, NSError *error) {
if (error){
NSLog(@"SCATTO: Salvataggio in library: ERRORE");
} else {
NSLog(@"SCATTO: Salvataggio in library: OK");
[self loadNewestPhoto];
}
}];