[iPhone Dev] Camera Swap

// Button Event
-(IBAction)CameraSwap:(id)sender
{
    NSArray *Current_inputs = self._captureSession.inputs;
    for ( AVCaptureDeviceInput *old_input in Current_inputs) {
        AVCaptureDevice *device = old_input.device;
        if ([device hasMediaType:AVMediaTypeVideo]) {
            AVCaptureDevicePosition position = device.position;
            AVCaptureDevice *newCamera = nil;
            AVCaptureDeviceInput *newInput = nil;
            if (position == AVCaptureDevicePositionFront) {
                newCamera = [self cameraWithPosition:AVCaptureDevicePositionBack];
            } else {
                newCamera = [self cameraWithPosition:AVCaptureDevicePositionFront];
            }
            
            newInput = [AVCaptureDeviceInput deviceInputWithDevice:newCamera error:nil];
            
            // Config Start
            [self._captureSession beginConfiguration];
            [self._captureSession removeInput:old_input];
            [self._captureSession addInput:newInput];
            [self._captureSession commitConfiguration];
            
            break;
        }
    }
        
}

-(AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position {
    NSArray *Camera_devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in Camera_devices) {
        if (device.position == position) {
            return device;
        }
    }
    return nil;
}

댓글

이 블로그의 인기 게시물

한글 2010 에서 Ctrl + F10 누르면 특수문자 안뜰 때

아이폰에서 RFID 사용하는 방법

VCC 와 GND 는 무엇일까?