AVCam saves full-screen image

I use AVCam made by apple for my custom camera view. Honestly, it’s not easy to understand what is going on in the AVCamViewController class if you see it for the first time.

Now I wonder how they set the frame of the captured image. I tried to find where some stylists or something like that, but I did not find them.

I searched on Google and found the answer here AVCam is not in full screen

But when I implemented this solution, I realized that he just made a real-time preview layer with the same size as my view, but when the application saves the image in the - (IBAction)snapStillImage:(id)sender method in the gallery, the images were still with two stripes on the left and right.

My question is how to remove these stripes or in which line in the apple source code to install this stuff?

As well as an additional subquery, how can I set the type, create only a photo, because the application asks me for “Microphone settings”, and I don’t need it, I just need to take a photo and what it is.

This code from Apple sources will save the image in the photo library.

 - (IBAction)snapStillImage:(id)sender { dispatch_async([self sessionQueue], ^{ // Update the orientation on the still image output video connection before capturing. [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]]; // 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]; UIImage *proccessingImage = [SAPAdjustImageHelper adjustImage:image]; NSNumber *email_id = [SAPCoreDataEmailHelper currentEmailId]; [SAPFileManagerHelper addImage:proccessingImage toFolderWithEmailId:email_id]; } }]; }); } 
+2
ios objective-c avcam avcapturesession
source share
2 answers

Are you setting a session preset?

You can use your session with the session settings set in AVCaptureSessionPresetPhoto .

For another subquery: you only need to add the output of AVCaptureStillImageOutput .

How to set up session pre-configuration?

 [session setSessionPreset:AVCaptureSessionPresetPhoto]; 

How to set up a session to use StillImageOutput only for taking photos and?

 - (void)viewDidLoad { [super viewDidLoad]; // Create the AVCaptureSession AVCaptureSession *session = [[AVCaptureSession alloc] init]; [self setSession:session]; // Setup the preview view [[self previewView] setSession:session]; // Setup the session Preset [session setSessionPreset:AVCaptureSessionPresetPhoto]; // Check for device authorization [self checkDeviceAuthorizationStatus]; dispatch_queue_t sessionQueue = dispatch_queue_create("session queue", DISPATCH_QUEUE_SERIAL); [self setSessionQueue:sessionQueue]; dispatch_async(sessionQueue, ^{ //[self setBackgroundRecordingID:UIBackgroundTaskInvalid]; NSError *error = nil; AVCaptureDevice *videoDevice = [AVCamViewController deviceWithMediaType:AVMediaTypeVideo preferringPosition:AVCaptureDevicePositionBack]; AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; if (error) { NSLog(@"%@", error); } if ([session canAddInput:videoDeviceInput]) { [session addInput:videoDeviceInput]; [self setVideoDeviceInput:videoDeviceInput]; dispatch_async(dispatch_get_main_queue(), ^{ // Why are we dispatching this to the main queue? // Because AVCaptureVideoPreviewLayer is the backing layer for AVCamPreviewView and UIView can only be manipulated on main thread. // Note: As an exception to the above rule, it is not necessary to serialize video orientation changes on the AVCaptureVideoPreviewLayer's connection with other session manipulation. [[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] setVideoOrientation:(AVCaptureVideoOrientation)[self interfaceOrientation]]; }); } AVCaptureStillImageOutput *stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; if ([session canAddOutput:stillImageOutput]) { [stillImageOutput setOutputSettings:@{AVVideoCodecKey : AVVideoCodecJPEG}]; [session addOutput:stillImageOutput]; [self setStillImageOutput:stillImageOutput]; } }); } 
+5
source share

To save the proportions, black margins are required, if you want to avoid them, you must change the videoGravity in AVCaptureVideoPreviewLayer or in the contentMode UIImageView , displaying the captured image.
> This is the expected behavior, do not understand your concern.

0
source share

All Articles