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

  • Home
  • SEARCH
  • 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 4108352
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:38:32+00:00 2026-05-20T21:38:32+00:00

It seems as though when I take a picture with the camera in portrait

  • 0

It seems as though when I take a picture with the camera in portrait mode, the UIImage has the correct size/aspect ratio (1536×2048 / 3:4) and orientation (Right), exported to a file (with UIImage.AsPNG().Save()), it always comes out in landscape mode (2048×1536, 4:3).

Is this for real, or am I doing something wrong? And is there a workaround, e.g. with ALAssetsLibrary.WriteImageToSavedPhotosAlbum?

Update: Originally I thought this also happened with UIImage.SaveToPhotosAlbum(), but on closer inspection I realize that the UIImage in that case was not the original from the camera, but rather one reconstituted from earlier AsPNG() saved data.

Update again: It looks like this is a general ‘feature’ of the iPhone camera, and the only way to fix it is by manually rotating the image. I tried porting this code to MT, as shown below, but what I seem to have done is invent a new way to create blank images of the right size and aspect ratio. Can anyone spot the bug?

public static class ImageUtils
{
    static float DefaultMaxSize = 960;

    public static UIImage ScaleAndRotateImage (UIImage image) {
        return ScaleAndRotateImage(image, DefaultMaxSize);
    }

    public static UIImage ScaleAndRotateImage (UIImage image, float maxSize)
    {
        CGImage imgRef = image.CGImage;

        float width = imgRef.Width;
        float height = imgRef.Height;

        CGAffineTransform transform = CGAffineTransform.MakeIdentity();

        RectangleF bounds = new RectangleF (0, 0, width, height);
        if (width > maxSize || height > maxSize) {
            float ratio = width / height;
            if (ratio > 1) {
                bounds.Width = maxSize;
                bounds.Height = bounds.Width / ratio;
            } else {
                bounds.Height = maxSize;
                bounds.Width = bounds.Height * ratio;
            }
        }

        float scaleRatio = bounds.Width / width;
        SizeF imageSize = new SizeF (imgRef.Width, imgRef.Height);
        float boundHeight;
        UIImageOrientation orient = image.Orientation;
        if (orient == UIImageOrientation.Up) {
            //EXIF = 1
            transform = CGAffineTransform.MakeIdentity();
        } else if (orient == UIImageOrientation.UpMirrored) {
            //EXIF = 2
            transform = CGAffineTransform.MakeTranslation (imageSize.Width, 0);
            transform.Scale (-1.0f, 1.0f);
        } else if (orient == UIImageOrientation.Down) {
            //EXIF = 3
            transform = CGAffineTransform.MakeTranslation (imageSize.Width, imageSize.Height);
            transform.Rotate ((float) Math.PI);
        } else if (orient == UIImageOrientation.DownMirrored) {
            //EXIF = 4
            transform = CGAffineTransform.MakeTranslation (0, imageSize.Height);
            transform.Scale (1.0f, -1.0f);
        } else if (orient == UIImageOrientation.LeftMirrored) {
            //EXIF = 5
            boundHeight = bounds.Height;
            bounds.Height = bounds.Width;
            bounds.Width = boundHeight;
            transform = CGAffineTransform.MakeTranslation (imageSize.Height, imageSize.Width);
            transform.Scale (-1.0f, 1.0f);
            transform.Rotate ((float)(3.0f * Math.PI / 2.0));
        } else if (orient == UIImageOrientation.Left) {
            //EXIF = 6
            boundHeight = bounds.Height;
            bounds.Height = bounds.Width;
            bounds.Width = boundHeight;
            transform = CGAffineTransform.MakeTranslation (0, imageSize.Width);
            transform.Rotate ((float)(3.0f * Math.PI / 2.0));
        } else if (orient == UIImageOrientation.RightMirrored) {
            //EXIF = 7
            boundHeight = bounds.Height;
            bounds.Height = bounds.Width;
            bounds.Width = boundHeight;
            transform = CGAffineTransform.MakeScale (-1.0f, 1.0f);
            transform.Rotate ((float)(Math.PI / 2.0));
        } else if (orient == UIImageOrientation.Right) {
            //EXIF = 8
            boundHeight = bounds.Height;
            bounds.Height = bounds.Width;
            bounds.Width = boundHeight;
            transform = CGAffineTransform.MakeTranslation (imageSize.Height, 0);
            transform.Rotate ((float)(Math.PI / 2.0));
        } else {
            throw new InvalidOperationException ("Invalid image orientation");
        }

        UIGraphics.BeginImageContext(bounds.Size);

        CGContext context = UIGraphics.GetCurrentContext ();

        if (orient == UIImageOrientation.Right || orient == UIImageOrientation.Left) {
            context.ScaleCTM (-scaleRatio, scaleRatio);
            context.TranslateCTM (-height, 0f);
        } else {
            context.ScaleCTM (scaleRatio, -scaleRatio);
            context.TranslateCTM (0f, -height);
        }

        context.ConcatCTM(transform);

        context.DrawImage (new RectangleF(0, 0, width, height), imgRef);
        UIImage imageCopy = UIGraphics.GetImageFromCurrentImageContext ();
        UIGraphics.EndImageContext ();

        return imageCopy;
    }
}
  • 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-20T21:38:33+00:00Added an answer on May 20, 2026 at 9:38 pm

    I finally got this to work. Here’s a gist which has the code:

    https://gist.github.com/890460

    and my blog post about it:

    http://www.fastchicken.co.nz/2011/03/28/scaling-and-rotating-an-image-in-monotouch/

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

Sidebar

Related Questions

No related questions found

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.