Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:15:07+00:00 2026-06-18T00:15:07+00:00

I am trying to set the AVFoundation camera size based on my UIImageView (selectedImage)

  • 0

I am trying to set the AVFoundation camera size based on my UIImageView (selectedImage) size like this:

    self.sess = [AVCaptureSession new];
    self.snapper = [AVCaptureStillImageOutput new];
    self.snapper.outputSettings = @{AVVideoCodecKey: AVVideoCodecJPEG};
    self.sess.sessionPreset = AVCaptureSessionPresetPhoto;
    [self.sess addOutput:self.snapper];
    AVCaptureDevice* cam = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice:cam error:nil];
    [self.sess addInput:input];
    AVCaptureVideoPreviewLayer* lay = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.sess];
    lay.videoGravity = AVLayerVideoGravityResizeAspectFill;
    lay.frame = selectedImage.frame;
   [self.view.layer addSublayer:lay];

In the app, it shows it just fine – 320X320 size, but when I look in the photo gallery, the saved image is longer than a square.

I also tried to remove lay.videoGravity = AVLayerVideoGravityResizeAspectFill; but then the image in the app is not filling the screen.

How can I set also the shot image size to be what the user sees in the camera with no extra tails?

the image as it looks after capturing in the app
the image how it is saved in the photo album
camera image no aspect fill

This is the code that saves the image to gallery:

AVCaptureConnection *vc = [self.snapper connectionWithMediaType:AVMediaTypeVideo];
// deal with image when it arrives
typedef void(^MyBufBlock)(CMSampleBufferRef, NSError*);
MyBufBlock h = ^(CMSampleBufferRef buf, NSError *err) {
    NSData* data = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:buf];
    UIImage* im = [UIImage imageWithData:data];
    dispatch_async(dispatch_get_main_queue(), ^{
        selectedImage.hidden = NO;
        selectedImage.contentMode = UIViewContentModeScaleAspectFill;
        selectedImage.clipsToBounds = YES;
        selectedImage.image = im;
        [self.previewLayer removeFromSuperlayer];
        self.previewLayer = nil;
        [self.sess stopRunning];
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library writeImageToSavedPhotosAlbum:[selectedImage.image CGImage] orientation:(ALAssetOrientation)[selectedImage.image imageOrientation] completionBlock:nil];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:15:08+00:00Added an answer on June 18, 2026 at 12:15 am

    I believe you’ll need to crop the image yourself; the reduced size of your viewfinder only affected its visible shape, not the amount of data it would be processing.

    An example on how to crop an image can be found at: How to properly crop an image taken on iPhone 4G (with EXIF rotation data)?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to set up a new spring project and im having this issue where
i am new to AVFoundation and i am trying to implement a video camera
Im trying to set image in window.opener from open window like this: $(document).ready(function(){ $('a').click(function
Trying to set this textbox <%= Html.TextBoxFor(m => m.IndicationCalculatorNewGroupName, new {propertyName = IndicationCalculatorNewGroupName, onchange
Trying to set up a self signed certificate, for our intranet's web services site.
Trying to set up a new project, and running into a weird issue. I
Trying to set a class based on my current controller or current route (URL
Trying to set this label to red I've got the following class: .redErrorText {
Trying to set up the svn commit with trac using this script. It is
Im trying to set up a variable and pass it constructor function essentailly like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.