1

在将图像捕获为 AVCaptureSession 会话运行到本地 NSMutableArray 时,我收到了一个 didReceiveMemoryWarning 调用。经过一番测试,我发现它发生在 ARRAY 达到一定数量时。

我认为这是因为我使用 UIImage 作为我添加到数组中的对象类型。保存这些图像的最佳格式是什么?

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

CVPixelBufferRef pixel_buffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixel_buffer];
CGImageRef ref = [self.context createCGImage:ciImage fromRect:ciImage.extent]; 

UIImage *image = [UIImage imageWithCGImage:ref scale:1.0 orientation:UIImageOrientationRight];

CGImageRelease(ref);

[self.capturingImageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
if (saveImages == YES) { //this a BOOL value that becomes YES when the user clicks the RECORDING button.
    [dImagesArray addObject:image];
}
}
4

2 回答 2

1

为什么不使用 AVCaptureVideoPreviewLayer 除非你正在做任何类型的过滤?出于性能原因,我建议使用 OpenGL 为委托方法渲染图像captureOutput:didOutputSampleBuffer:fromConnection:这是一个示例...... https://developer.apple.com/library/ios/qa/qa1702/_index.html

于 2014-09-10T03:46:33.860 回答
1

您可以将图像保存为最适合您需要的任何格式:这可能是 JPG 或 PNG。前者较小,但有损,后者是无损的。因此,如果图像质量对您来说非常重要,请使用 PNG。如果没有,我会使用 JPG(这将具有占用更少磁盘空间的额外优势)。

您目前没有将任何图像保存到磁盘,只是将它们保存在数组中的内存中,这就是导致您出现问题的原因。您可以通过多种方式处理此问题,具体取决于您希望应用程序执行的操作。您需要将图像保存到磁盘吗?如果是这样,可以随时限制内存中允许的图像数量,并在需要时将它们转储到磁盘。或者您可能只是对图像进行一些分析,在这种情况下,您可以在不再需要它们时释放它们。

于 2012-12-26T11:58:04.670 回答