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 7639187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:21:20+00:00 2026-05-31T08:21:20+00:00

I got an app, where i tried to implement custom camera. This is source

  • 0

I got an app, where i tried to implement custom camera. This is source code:

AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

    captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
    [self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];

    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    //device.position ;
    NSError *error = nil;
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
    [session addInput:input];
    [session startRunning];

    stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
    [stillImageOutput setOutputSettings:outputSettings];

    [session addOutput:stillImageOutput];

Then i tried to create photo and send it to other view controller:

-(IBAction) captureNow
{
    AVCaptureConnection *videoConnection = nil;
    for (AVCaptureConnection *connection in stillImageOutput.connections)
    {
        for (AVCaptureInputPort *port in [connection inputPorts])
        {
            if ([[port mediaType] isEqual:AVMediaTypeVideo] )
            {
                videoConnection = connection;
                break;
            }
        }
        if (videoConnection) { break; }
    }

    //NSLog(@"about to request a capture from: %@", stillImageOutput);

    AcceptingPhotoViewController *photo = [[AcceptingPhotoViewController alloc] initWithNibName:@"AcceptingPhotoViewController" bundle:nil];

    [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
     {
         CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);

         NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
         UIImage *image = [[UIImage alloc] initWithData:imageData];

         photo.image = [[UIImage alloc] init ];
         photo.image = image;
         photo.photoFromCamera = YES;

         [self.navigationController pushViewController:photo animated:NO];
     }];
}

But in my target class this image is rotating to the left on 90 degrees:
enter image description here

I tried to rotate it back:

float newSide = MAX([image size].width, [image size].height);
                    CGSize size =  CGSizeMake(newSide, newSide);
                    UIGraphicsBeginImageContext(size);
                    CGContextRef ctx = UIGraphicsGetCurrentContext();
                    CGContextTranslateCTM(ctx, newSide/2, newSide/2);
                    CGContextRotateCTM(ctx, 1.57079633);
                    CGContextDrawImage(UIGraphicsGetCurrentContext(),CGRectMake(-[image size].width/2,-[image size].height/2,size.width, size.height),image.CGImage);
                    UIImage *i = UIGraphicsGetImageFromCurrentImageContext();
                    UIGraphicsEndImageContext();
                    image = i;

My image rotated on the right, but it display mirrored and stretch.

Any help? Can i rotate in other way, or maybe i should take photo not like this?

  • 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-05-31T08:21:21+00:00Added an answer on May 31, 2026 at 8:21 am

    I found solve of this problem:

    I rotate and transform image in this way

    UIView* rotatedViewBox = [[UIView alloc] initWithFrame: CGRectMake(0, 0, image.size.width, image.size.height)];
                        float angleRadians = 90 * ((float)M_PI / 180.0f);
                        CGAffineTransform t = CGAffineTransformMakeRotation(angleRadians);
                        rotatedViewBox.transform = t;
                        CGSize rotatedSize = rotatedViewBox.frame.size;
    
                    UIGraphicsBeginImageContext(rotatedSize);
                    CGContextRef bitmap = UIGraphicsGetCurrentContext();
                    CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
                    CGContextRotateCTM(bitmap, angleRadians);
    
                    CGContextScaleCTM(bitmap, 1.0, -1.0);
                    CGContextDrawImage(bitmap, CGRectMake(-image.size.width / 2, -image.size.height / 2, image.size.width, image.size.height), [image CGImage]);
    
                    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
                    UIGraphicsEndImageContext();
                    image = newImage;
    
                    CGSize newSize = CGSizeMake(image.size.height, image.size.width);
                    UIGraphicsBeginImageContext(newSize);
    
                    // Tell the old image to draw in this new context, with the desired
                    // new size
                    [image drawInRect:CGRectMake(0,0,image.size.height,image.size.width)];
    
                    // Get the new image from the context
                    UIImage* newImage2 = UIGraphicsGetImageFromCurrentImageContext();
    
                    // End the context
                    UIGraphicsEndImageContext();
    
                    image = newImage2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am bulding an app and I tried YSlow and got Grade F on
I got an app with an UIAlertView . When this alertView close, i wanna
I got an app, with label and big text. I tried to fit label's
I got an error like this - Terminating app due to uncaught exception 'NSInvalidArgumentException',
I need to implement the code for my app to buffer and play my
My app got rejected for not setting the do not back up attribute to
I got an app running on my SQL Server that is starting to slow
I got a app who has Sonata User bundle and Sonata Admin bundle ,
I got an app with UITableView. Every cell has accessory. But i cant set
I got an app with iCarousel library. All works perfect. But i need cover

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.