3

我已经使用 AVCaptureSession 和苹果 AVCam 演示应用程序中的许多代码构建了自己的自定义相机类。基本上,我用来捕获图像的功能是来自苹果应用程序的逐字记录,但是当我拍摄照片时,我会在控制台中收到收到的内存警告。它不会一直发生,但几乎总是在第一张照片上。这是我的问题的代码..

- (void)capImage { //method to capture image from AVCaptureSession video feed
    dispatch_async([self sessionQueue], ^{
        // Update the orientation on the still image output video connection before capturing.

        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];


        [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:(AVCaptureVideoOrientation)orientation];

        // Flash set to Auto for Still Capture
        //[AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];

        // Capture a still image.
        [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

            if (imageDataSampleBuffer)
            {
                NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
                UIImage *image = [[UIImage alloc] initWithData:imageData];
                [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:nil];
                [self processImage:[UIImage imageWithData:imageData]];
            }
        }];
    });
}

任何想法为什么会发生这种情况?

4

0 回答 0