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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:14:39+00:00 2026-06-07T00:14:39+00:00

I made an iphone app to capture image from camera and to set that

  • 0

I made an iphone app to capture image from camera and to set that image in next view. But the problem is that image is rotated. i.e landscape image becomes potraite and protraite image becomes landscape.
I have referred many codes but could not get solution.

My code is :

- (void)btnCapturePressed
{
 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {

            picker=[[UIImagePickerController alloc] init];
            picker.delegate=self;

            [picker setAllowsEditing:YES];

            picker.sourceType=UIImagePickerControllerSourceTypeCamera;
            //[self.navigationController pushViewController:(UIViewController *)ipc animated:YES];
            [self presentModalViewController:picker animated:YES];
            [picker release];
      }
}

-(void) imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo :(NSDictionary *)info
{
           UIImage *imageToScale=[info objectForKey:UIImagePickerControllerOriginalImage];

            imgView = [[UIImageView alloc] initWithImage:imageToScale];

            [picker presentModalViewController:cropper animated:YES];
}

I have also refered the link. with same problem, but could not find the solution.

Please help me.

Thanks.

  • 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-07T00:14:40+00:00Added an answer on June 7, 2026 at 12:14 am

    So for that at the time of image take store the orientation of the device and pass it to the method below as parameter
    Here just give any name to method and pass the parameter orientation

    switch (orientation) {
                case UIDeviceOrientationPortrait:
                    [featureLayer setAffineTransform:CGAffineTransformMakeRotation(DegreesToRadians(0.))];
                    break;
                case UIDeviceOrientationPortraitUpsideDown:
                    [featureLayer setAffineTransform:CGAffineTransformMakeRotation(DegreesToRadians(180.))];
                    break;
                case UIDeviceOrientationLandscapeLeft:
                    [featureLayer setAffineTransform:CGAffineTransformMakeRotation(DegreesToRadians(90.))];
                    break;
                case UIDeviceOrientationLandscapeRight:
                    [featureLayer setAffineTransform:CGAffineTransformMakeRotation(DegreesToRadians(-90.))];
                    break;
                case UIDeviceOrientationFaceUp:
                case UIDeviceOrientationFaceDown:
                default:
                    break; // leave the layer in its last known orientation
            }
    

    and the macro I have used here DegreesToRadians() is as follow

    static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
    

    This will definitely works.

    Happy Coding 🙂

    EDIT

    If the above code doesn’t work well then use this one

    @interface UIImage (RotationMethods)
    - (UIImage *)imageRotatedByDegrees:(CGFloat)degrees;
    @end
    
    @implementation UIImage (RotationMethods)
    
    - (UIImage *)imageRotatedByDegrees:(CGFloat)degrees 
    {   
        // calculate the size of the rotated view's containing box for our drawing space
        UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.size.width, self.size.height)];
        CGAffineTransform t = CGAffineTransformMakeRotation(DegreesToRadians(degrees));
        rotatedViewBox.transform = t;
        CGSize rotatedSize = rotatedViewBox.frame.size;
    
        // Create the bitmap context
        UIGraphicsBeginImageContext(rotatedSize);
        CGContextRef bitmap = UIGraphicsGetCurrentContext();
    
        // Move the origin to the middle of the image so we will rotate and scale around the center.
        CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
    
        //   // Rotate the image context
        CGContextRotateCTM(bitmap, DegreesToRadians(degrees));
    
        // Now, draw the rotated/scaled image into the context
        CGContextScaleCTM(bitmap, 1.0, -1.0);
        CGContextDrawImage(bitmap, CGRectMake(-self.size.width / 2, -self.size.height / 2, self.size.width, self.size.height), [self CGImage]);
    
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newImage;
    
    }
    @end
    

    and then call the above function as below

    switch (orientation) {
            case UIDeviceOrientationPortrait:
                image = [image imageRotatedByDegrees:0];
                break;
            case UIDeviceOrientationPortraitUpsideDown:
                image = [image imageRotatedByDegrees:180];
                break;
            case UIDeviceOrientationLandscapeLeft:
                image = [image imageRotatedByDegrees:-90];
                break;
            case UIDeviceOrientationLandscapeRight:
                image = [image imageRotatedByDegrees:90];
                break;
            case UIDeviceOrientationFaceUp:
            case UIDeviceOrientationFaceDown:
            default:
                break; // leave the layer in its last known orientation
        }   
    

    If the image is not in required orientation then add 90 to all of the above imageRotatedByDegrees‘s argument (i.e. if it is 0 then it will be 0+90) or as you required.

    EDIT 1

    UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an app that implements the iPhone's camera. When the user finishes
I've made a universal iPhone/iPad app (transitioned from iPhone only), but in a future
i made an iPhone app that uses camera. It works fine in iPhone, no
I've made a hundred of screenshots from iPhone thru Organizer but it looks like
I have made an iPhone app with localized versions. It mostly works fine, but
I made an iPhone app that allows data entry. Over the past month I
If a URL request is made from an iPhone app, is it possible for
I am close to complete an iPhone app that aggregates information from many businesses.
I made an iPhone app that represents my job offer site. I want the
I've made an IPhone App that communicates to a service by calling a webservice

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.