-
The problem
Leaders arrange tasks, write a photo function, the interface with the system photo a little different
After taking a photo, the bottom shows that the photo was taken, and there is a photo upper limit.
Click on the photo taken, you can preview, zoom in and out to view
-
Train of thought
System photo definitely not working, can only be customized, did not mention whether to take photos prohibited sound requirements [not candid, serious person]
In principle, simple is not complex, take AVCapturePhotoOutput brick
-
Smooth your
First of all, you need a layer for the current scene, which is not mentioned here.
Second, define session + photoOutput
Again, define the photo event
Finally, the agent gets the photo
-
serving
- 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]; } Copy the code
- 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) { make.left.equalTo(self.view); make.top.equalTo(self.topView.mas_bottom); make.bottom.equalTo(self.collect.mas_top); make.right.equalTo(rightView.mas_left); }]; Copy the code
- Set the photoOutput
self.photoOutput = [[AVCapturePhotoOutput alloc] init]; if ([self.session canAddOutput:self.photoOutput]) { [self.session addOutput:self.photoOutput]; } [self.photoOutput.connections.lastObject setVideoOrientation:AVCaptureVideoOrientationLandscapeRight]; Copy the code
- session start
[self.session startRunning]; Copy the code
- Photo click
AVCapturePhotoSettings *set = [AVCapturePhotoSettings photoSettings]; [self.photoOutput capturePhotoWithSettings:set delegate:self]; Copy the code
- AVCapturePhotoCaptureDelegate
#pragma mark - AVCapturePhotoCaptureDelegate -(void)captureOutput:(AVCapturePhotoOutput *)output DidFinishProcessingPhoto photo: (AVCapturePhoto *) error: (NSError *) error API_AVAILABLE (ios (11.0)) {if (! NSData *data = [photo fileDataRepresentation]; NSData *data = [photo fileDataRepresentation]; UIImage *image = [UIImage imageWithData:data]; // Image}}Copy the code
-
Game Over.
See me Tomorrow, haha