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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:28:36+00:00 2026-06-11T20:28:36+00:00

This is part of a big project, but my problem can be simplified as:

  • 0

This is part of a big project, but my problem can be simplified as:
I have a simple view with an ImageView and a “Rotate” button. Whenever I press the button, the image inside the ImageView will rotate 90 degree. From much of what I’ve found on StackOverflow and other sites, this should work (please note that my image is a square image, which has width and height equal to 464):

- (UIImage *) getRotatedImageFromImage:(UIImage*)image:(int)rotate_index
{
    UIImage *rotatedImage;

    // Get image width, height of the bounding rectangle
    CGRect boundingRect = CGRectMake(0, 0, image.size.width, image.size.height);
    NSLog(@"width = %f, height = %f",boundingRect.size.width,boundingRect.size.height);
    NSLog(@"rotate index = %d",rotate_index);

    // Create a graphics context the size of the bounding rectangle
    UIGraphicsBeginImageContext(boundingRect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextRotateCTM(context, rotate_index*M_PI/2);

    // Draw the image into the context

    [image drawInRect:boundingRect];

    // Get an image from the context
    rotatedImage = UIGraphicsGetImageFromCurrentImageContext();

    // Clean up
    UIGraphicsEndImageContext();

    NSLog(@"rotatedImage size = (%f, %f)",rotatedImage.size.width,rotatedImage.size.height);

    return rotatedImage;
}

- (IBAction) rotateImage
{
    NSLog(@"rotate image");
    rotateIndex++;
    if (rotateIndex >= 4)
        rotateIndex = 0;
    [imageView setImage: [self getRotatedImageFromImage:imageToSubmit :rotateIndex]];
}

But it doesn’t work for some reasons. What I have is: when pressing the button, the image only appears when rotateIndex gets to 0, and the image is the same as the original image (which is expected). When rotateIndex is 1, 2, 3, the imageView displays nothing, even though the size of rotatedImage printed out is correct (i.e. 464 x 464) .
Could anyone tell me what’s going wrong?
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-11T20:28:38+00:00Added an answer on June 11, 2026 at 8:28 pm

    I was able to solve my problem. Here is my solution, using CGImageRef and [UIImage imageWithCGImage: scale: orientation:]

    CGImageRef cgImageRef = CGBitmapContextCreateImage(context); 
    UIImageOrientation imageOrientation; 
    switch (rotate_index) { 
        case 0: imageOrientation = UIImageOrientationUp; break; 
        case 1: imageOrientation = UIImageOrientationLeft; break; 
        //2 more cases for rotate_index = 2 and 3 
    } 
    rotatedImage = [UIImage imageWithCGImage:cgImageRef scale:1.0 orientation:imageOrientation];`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a personal project very simple but this is part of
I have a project where a big part of the UI a notebook, where
currently I have to change a view, a big part of the view code
I'm developing a game, a big part of this game, is about scrolling a
This part of an app that I am working on, I have the following
I have this part of script from my GAE application which uses webapp2, which
I want to code this part of a VB6 application in c#. How can
The end goal of this part of my project is to be able to
A part of big project is a payment system, that I would like to
so I need to maintain this old legacy project, where one part of it

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.