Full screen camera

I am having problems with AVCapture.

Backstory: I made a new storyboard for my iPad app by copying the iPhone storyboard and changing the source code of the new storyboard to add .iPad where needed. My app is currently only using portrait mode.

However, AVCapture (which I use to show the live feed of the camera) fills part of the screen with only black bars. I also noticed that this is done on an iPhone with a 3.5-inch screen.

I will add the code as requested.

Please make all instructions super easy to follow, this is my first app and I am a newbie.

Thank!! Branch

EDIT: I tried this code from Apple documentation but it didn't work:

AVCaptureSession *captureSession; AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession]; UIView *aView; previewLayer.frame = aView.bounds; [aView.layer addSublayer:previewLayer];

+3


source to share


2 answers


The aspect ratio of the camera is different from the aspect ratio of the iPad. You can change the property of videoGravity

yours AVCaptureVideoPreviewLayer

to fill the entire layer (this cuts off the input, but you won't see the lines):

captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

      



You will still get all of the camera input, not just the layer preview when you actually capture the image. You will need to do the math (geometry) based on your UI to rotate and crop it to get the image the user actually sees.

+6


source


Perhaps my problem is similar. Follow these steps to resolve:

  • set preset session as AVCaptureSessionPresetHigh
  • set previewLayer videoGravity property for AVLayerVideoGravityResizeAspectFill
  • set preview frame as device screen limits

I posted my solutions today for reporting an issue using DBCamera, here is the full content:


This may not be a big thing, but it's useful for anyone who cares about why a photo taken from a custom full-screen camera view doesn't look quite accurate.

I noticed that using a custom camera view that is subclassed from DBCameraView and calling openCustomCamera from the given example will create a full screen preview. And the captured photo from this full-screen preview on the iPhone 5s and 6s will get extra space on both sides, which means the final photo won't look exactly the same as it did in the preview before the camera was launched.



This is because:
1. Preset session in code - AVCaptureSessionPresetPhoto
2. Preview. Videographer graphics set to AVLayerVideoGravityResizeAspectFill 3.Preview
frame - device screen boundaries

VideoGravity for preview - default AVLayerVideoGravityResizeAspect. When you preset the session as AVCaptureSessionPresetPhoto and set the preview size as screen size, the system fails to satisfy both conditions because I think AVCaptureSessionPresetPhoto will adjust the preview size, which resizes to fit the high resolution shot (e.g. 4 : 3?). The aspect ratio does not seem to be the same as the screen (less obvious for 4s) so you can see black areas both above and below, even if you set the preview frame equal to the edges of the screen... However, DBCamera sets AVLayerVideoGravityResizeAspectFill to videoGravity in code. This will cause the preview to try to fill the entire screen and maintain its correct aspect ratio. The custom camera view appears to fill the entire screen of the device, but the actual preview is larger than the screen size with additional spaces expanded beyond the screen on both the left and right sides.

To fix the problem, to get the same photo from the full screen preview, set AVCaptureSessionPresetHigh instead of AVCaptureSessionPresetPhoto. This will work. The disadvantage is that the quality of the photo cannot remain the same, that is, a trade-off.

Correct me if I am wrong and hopefully this helps.

https://github.com/danielebogo/DBCamera/issues/194

+3


source







All Articles