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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:34:05+00:00 2026-05-22T12:34:05+00:00

I need to scale the resolution of an image coming from a view layer

  • 0

I need to scale the resolution of an image coming from a view layer in an iPhone application. The obvious way is to specify a scale factor in UIGraphicsBeginImageContextWithOptions, but any time the scale factor is not 1.0 then quality of the image goes to pot — far more than would be expected from the loss of pixels.

I’ve tried several other scaling techniques, but they all seem to revolve around CGContext stuff and all appear to do the same thing.

Simply changing image “size” (without changing the dot resolution) isn’t sufficient, mostly because that info seems to be discarded very quickly by other hands in the pipeline (the image will be converted to a JPG and emailed).

Is there any other way to scale an image on iPhone?

  • 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-22T12:34:06+00:00Added an answer on May 22, 2026 at 12:34 pm

    About UIImage resize problem, this post give many ways to handle UIImage object. The UIImage has some orientation problems need to be fixed. This and Another post will address it.


    -(UIImage*)resizedImageToSize:(CGSize)dstSize
    {
        CGImageRef imgRef = self.CGImage;
        // the below values are regardless of orientation : for UIImages from Camera, width>height (landscape)
        CGSize  srcSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef)); // not equivalent to self.size (which is dependant on the imageOrientation)!
    
        /* Don't resize if we already meet the required destination size. */
        if (CGSizeEqualToSize(srcSize, dstSize)) {
            return self;
        }
    
        CGFloat scaleRatio = dstSize.width / srcSize.width;
    
        // Handle orientation problem of UIImage
        UIImageOrientation orient = self.imageOrientation;
        CGAffineTransform transform = CGAffineTransformIdentity;
        switch(orient) {
    
            case UIImageOrientationUp: //EXIF = 1
                transform = CGAffineTransformIdentity;
                break;
    
            case UIImageOrientationUpMirrored: //EXIF = 2
                transform = CGAffineTransformMakeTranslation(srcSize.width, 0.0);
                transform = CGAffineTransformScale(transform, -1.0, 1.0);
                break;
    
            case UIImageOrientationDown: //EXIF = 3
                transform = CGAffineTransformMakeTranslation(srcSize.width, srcSize.height);
                transform = CGAffineTransformRotate(transform, M_PI);
                break;
    
            case UIImageOrientationDownMirrored: //EXIF = 4
                transform = CGAffineTransformMakeTranslation(0.0, srcSize.height);
                transform = CGAffineTransformScale(transform, 1.0, -1.0);
                break;
    
            case UIImageOrientationLeftMirrored: //EXIF = 5
                dstSize = CGSizeMake(dstSize.height, dstSize.width);
                transform = CGAffineTransformMakeTranslation(srcSize.height, srcSize.width);
                transform = CGAffineTransformScale(transform, -1.0, 1.0);
                transform = CGAffineTransformRotate(transform, 3.0 * M_PI_2);
                break;  
    
            case UIImageOrientationLeft: //EXIF = 6  
                dstSize = CGSizeMake(dstSize.height, dstSize.width);
                transform = CGAffineTransformMakeTranslation(0.0, srcSize.width);
                transform = CGAffineTransformRotate(transform, 3.0 * M_PI_2);
                break;  
    
            case UIImageOrientationRightMirrored: //EXIF = 7  
                dstSize = CGSizeMake(dstSize.height, dstSize.width);
                transform = CGAffineTransformMakeScale(-1.0, 1.0);
                transform = CGAffineTransformRotate(transform, M_PI_2);
                break;  
    
            case UIImageOrientationRight: //EXIF = 8  
                dstSize = CGSizeMake(dstSize.height, dstSize.width);
                transform = CGAffineTransformMakeTranslation(srcSize.height, 0.0);
                transform = CGAffineTransformRotate(transform, M_PI_2);
                break;  
    
            default:  
                [NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];  
    
        }  
    
        /////////////////////////////////////////////////////////////////////////////
        // The actual resize: draw the image on a new context, applying a transform matrix
        UIGraphicsBeginImageContextWithOptions(dstSize, NO, self.scale);
    
        CGContextRef context = UIGraphicsGetCurrentContext();
    
           if (!context) {
               return nil;
           }
    
        if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
            CGContextScaleCTM(context, -scaleRatio, scaleRatio);
            CGContextTranslateCTM(context, -srcSize.height, 0);
        } else {  
            CGContextScaleCTM(context, scaleRatio, -scaleRatio);
            CGContextTranslateCTM(context, 0, -srcSize.height);
        }
    
        CGContextConcatCTM(context, transform);
    
        // we use srcSize (and not dstSize) as the size to specify is in user space (and we use the CTM to apply a scaleRatio)
        CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, srcSize.width, srcSize.height), imgRef);
        UIImage* resizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return resizedImage;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a way to have a gray scale image in an ImageView and
I need to scale View by setting the scale factor in percents. I need
I need to scale down an image, but in a sharp way. In Photoshop
I need to scale image to small and store that image in to blackberry
I am working on one component where I need to scale and rotate image.
which algorithm to use to scale down 32Bit RGB IMAGE to custom resolution? Algorithm
I need to scale down an image that has a height or width greater
I have an application (an IP conferencing service) that I need to scale. It
We need to think big and our applications need to scale in order to
I have images that need to scale to the screen's size. The images will

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.