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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:32:30+00:00 2026-06-03T18:32:30+00:00

I have been googling around a bit and can’t seem to find an solution.

  • 0

I have been googling around a bit and can’t seem to find an solution. Here is my problem. I need to resize an UIImage to a specific size-namely a size so that the width and height are both powers of two. My images are coming from the camera, so the dimensions are not powers of two. I need to keep the entire image, while maintain the correct aspect-ie aspect fit mode. I know how to resize a UIImage, but I can’t figure out how to resize the image and add whitespace on the top and bottom appropriately to keep the proper overall image size, while retaining the correct aspect. Does anyone have insight on this?

BTW, here is my current resizing code(just resizes)

- (UIImage *) resizeImage:(UIImage *)initialImage
{
    CGSize newSize = CGSizeMake(256, 256);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [initialImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}

and I tried using this blog, but it does give me the proper image size when I specify UIViewContentModeScaleAspectFit for the content mode.

  • 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-03T18:32:32+00:00Added an answer on June 3, 2026 at 6:32 pm

    a eazy way to do that is

    put your image into a UIImageView, set the size you want with the whitespace and white backgournd color, then set the UIViewContentModeScaleAspectFit mode

    then turn it to a UIImage

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:yourFrame];
    imageView.image = yourImage;
    imageView.contentMode = UIViewContentModeScaleAspectFit ;
    imageView.backgroundColor = [UIColor whiteColor];
    
    UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, imageView.opaque, 0.0);
    [imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
    //the image you want
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    you got it

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

Sidebar

Related Questions

I've been googling around for a bit but I can't seem to find an
I looked around for a bit here and have been googleing for hours with
Been googling around but I can't find any help on this. I am trying
I've been googling around and I still can't get it. Some people say: here
i have been googling around wether PHP can handle to print a receipt and
Not sure if this exists as I have been googling all around and can't
I've been googling around and I just can't find a simple answer to this.
I have been googling around this issue, but could not find clear and definitive
I've been googling around, and I can't find the answer I'm looking for. Say
I have been Googling a problem that I have with trying to integrate the

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.