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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:55:07+00:00 2026-05-22T14:55:07+00:00

When we resizing the image (after downloading and before storing that in document directory),

  • 0

When we resizing the image (after downloading and before storing that in document directory), by the following code:

-(UIImage *)resizeImage:(UIImage *)image withSize:(CGSize)newSize
{
    float actualHeight = image.size.height;
    float actualWidth = image.size.width;
    float imgRatio = actualWidth/actualHeight;
    float maxRatio = newSize.width/newSize.height;

    if(imgRatio!=maxRatio){
        if(imgRatio < maxRatio){
            imgRatio = newSize.width / actualHeight;
            actualWidth = imgRatio * actualWidth;
            actualHeight = newSize.width;
        }
        else{
            imgRatio = newSize.height / actualWidth;
            actualHeight = imgRatio * actualHeight;
            actualWidth = newSize.height;
        }
    }
    CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight);
    UIGraphicsBeginImageContext(rect.size);
    [image drawInRect:rect];
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //[resizedImage release];
    return [resizedImage autorelease];
}

this produce a re sized image with the thin white line added towards it’s orientation(as if image is landscape white line is added to it’s bottom and if image is portrait white line is added to it’s right hand).

please tell that, how to get rid of that white line?

Thank you.

  • 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-22T14:55:08+00:00Added an answer on May 22, 2026 at 2:55 pm

    Although the size is specified in floating point units, the actual image is always an integral number of pixels.

    When you calculate the new size to preserve the aspect ratio, you will typically have only one of the sides as a whole number of pixels, while the other scales to have some fractional part. When you then draw the old image into that rect, it doesn’t quite fill the new image. So what you see as a white line is the graphics system’s way of rendering the pixels that are part image, part background.

    In essence, what you want to do is not quite possible, so you need to fudge it somehow. There are several possibilities:

    • Scale the image such that the aspect ratio is not perfectly preserved but you have integral values, for example by rounding:

      actualWidth = round(imgRatio * actualWidth);
      
    • Maintain the aspect ratio but clip the fractional edge. The easiest way to do this is probably to make the image context a little smaller:

      UIGraphicsBeginImageContext(CGSizeMake(floor(actualWidth), floor(actualHeight)));
      [image drawInRect:rect];
      
    • Just fill the background first with some colour that’s less obvious than white. This is a dreadful kludge, obviously, but could be effective in the right circumstances, for example if you’re always drawing the image against a black background.

    On a separate note, you can’t call anything after return, so your final release line isn’t doing anything. This is just as well because the image returned from UIGraphicsGetImageFromCurrentImageContext is autoreleased — you should not be releasing it anyway.

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

Sidebar

Related Questions

Does anyone know of any good image resizing libraries that will handling resizing large
The code below works very well for resizing an image by aspect ratio by
I have a user-uploaded image pulled from the database that I am resizing smaller
I am resizing an image that is uploaded and I am creating a new
Loading the image one time works as done in the following steps (for code
This is driving me crazy, so... When resizing image to small thumbnail, resulting image
I'm working on a JavaScript image resizing feature which rely on the IE only
I'm using this php class ( http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php ) for creating the different sized images
I am using the iPhone camera to capture an image and them resizing and
The .NET libraries do an excellent job at resizing images that look great: Bitmap

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.