在AVCaptureSession会话运行到本地NSMutableArray时捕获图像时,我收到了一个didReceiveMemoryWarning调用。在稍微测试了一下之后,我发现当数组达到一定数量时就会发生这种情况。
我假设这是因为我使用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];
}
}发布于 2012-12-26 19:58:05
您可以将图像保存为最适合您需要的任何格式:这可能是JPG或PNG格式。前者较小,但有损,后者是无损的。因此,如果图像质量对您非常重要,请使用PNG。如果不是,我会使用JPG(它的额外优势是占用更少的磁盘空间)。
您当前没有将任何图像保存到磁盘,只是将它们保存在内存中的一个数组中,这就是给您带来问题的原因。你可以通过多种方式来处理这个问题,这取决于你想让你的应用程序做什么。您是否需要将图像保存到磁盘?如果是这样的话,可以在任何时候设置内存中允许的图像数量的限制,并在需要时将它们转储到磁盘。或者,您可能只是在对图像进行一些分析,在这种情况下,您可以在不再需要它们时将其释放。
发布于 2014-09-10 11:46:34
为什么不使用AVCaptureVideoPreviewLayer,除非您正在进行任何类型的过滤?出于性能原因,我建议使用OpenGL为委托方法captureOutput:didOutputSampleBuffer:fromConnection:渲染图像,下面是一个示例...https://developer.apple.com/library/ios/qa/qa1702/_index.html
https://stackoverflow.com/questions/14040145
复制相似问题