5

I have a code that set a camera view as a subview, what i need is when i click a button it takes a picture from this AVCaptureSession and save it in to the photo library, how can i achive this?

Heres is my code:

AVCaptureSession *session = [[AVCaptureSession alloc] init]; AVCaptureOutput *output = [[AVCaptureStillImageOutput alloc] init]; [session addOutput:output];

    //Setup camera input
    NSArray *possibleDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    //You could check for front or back camera here, but for simplicity just grab the first device
    AVCaptureDevice *device = [possibleDevices objectAtIndex:1];

    NSError *error = nil;
    // create an input and add it to the session
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; //Handle errors

    //set the session preset
    session.sessionPreset = AVCaptureSessionPresetMedium; //Or other preset supported by the input device
    [session addInput:input];

    AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];

    previewLayer.affineTransform = CGAffineTransformMakeRotation(M_PI_2);
    //Set the preview layer frame
    previewLayer.frame = CGRectMake(45, 55, 512, 387);
    //Now you can add this layer to a view of your view controller
    [self.cameraPlace.layer addSublayer:previewLayer];
    [session startRunning];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Fernando Santiago
  • 2,128
  • 10
  • 44
  • 75
  • possible duplicate of [ios capturing image using AVFramework](http://stackoverflow.com/questions/8924299/ios-capturing-image-using-avframework) – Venk Oct 31 '13 at 04:49
  • There are n number of samples and description links available on internet. Before asking question Browse it, some of the related links, http://www.musicalgeometry.com/?p=1297 http://stackoverflow.com/questions/8264749/capturing-images-from-avcapturesession http://stackoverflow.com/questions/8924299/ios-capturing-image-using-avframework http://stackoverflow.com/questions/9312832/avcapturesession-specify-resolution-and-quality-of-captured-images-obj-c-iphone – Venk Oct 31 '13 at 04:49

0 Answers0