Avcapturephotooutput for IOS photo customization

  • problem

    Leaders arrange tasks, write a photo function, the interface is a little different from the system photo

    After taking photos, the bottom shows the photos taken. There is an upper limit for taking photos

    Click on the taken photos to preview, zoom in and out

  • thinking

    The system can’t take photos. It can only be customized. It doesn’t mention the need to take photos without sound

    In principle, it can be simple but not complex

  • Smooth it out

    First of all, you need a temporary layer of the current scene. I won’t mention it here. Please refer to the previous article [IOS before customizing the camera]

    Second, define session + photooutput

    Thirdly, define the photographing event

    Finally, get the photo from the agent

  • Serve

    • Session defines input settings

      self.session = [[AVCaptureSession alloc] init];
      self.session.sessionPreset = AVCaptureSessionPresetPhoto;
      AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
      self.dInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
      if ([self.session canAddInput:self.dInput]) {
          [self.session addInput:self.dInput];
    • Photo scene layer

      self.preView = [[AVPreView alloc] init];
      self.preView.backgroundColor = [UIColor colorWithHexs:0x3f3f3f];
      self.preView.session = self.session;
      [self.preView setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
      [self.view addSubview:self.preView];
      [self.preView mas_makeConstraints:^(MASConstraintMaker *make) {
    • Set up photooutput

      self.photoOutput = [[AVCapturePhotoOutput alloc] init];
      if ([self.session canAddOutput:self.photoOutput]) {
          [self.session addOutput:self.photoOutput];
      [self.photoOutput.connections.lastObject setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
    • session start

      [self.session startRunning];
    • Photo Click

      AVCapturePhotoSettings *set = [AVCapturePhotoSettings photoSettings];
      [self.photoOutput capturePhotoWithSettings:set delegate:self];
    • AVCapturePhotoCaptureDelegate

      #pragma mark - AVCapturePhotoCaptureDelegate
      -(void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(NSError *)error  API_AVAILABLE(ios(11.0)) {
          if (!error) {
              //If you use this method to get pictures, there may be rotation problems in the pictures. You can adjust the pictures when you use them
              NSData *data = [photo fileDataRepresentation];
              UIImage *image = [UIImage imageWithData:data];
              //Yes, it's the image above
  • Game Over.

    See me Tomorrow, haha

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]