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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:11:25+00:00 2026-06-13T10:11:25+00:00

I have a demo app here https://github.com/rdetert/image-transform-test After importing an image, you can pinch,

  • 0

I have a demo app here https://github.com/rdetert/image-transform-test

After importing an image, you can pinch, zoom, rotate the image. What I want to do is save out a 640x480 image (landscape mode) that looks identical to the live preview. So if there are 100px bars of empty space on the sides, I need the same empty bars in the final output (scaled appropriately).

This is proving to be more difficult than I thought it would be. I can’t quite get it to come out right after days of working on it.

The magic method that generates the final image is called -(void)generateFinalImage

Good luck! 😉

EDIT

Demo App Screenshot

The green rectangle represents the actual area the imported image can be pinched, zoomed and rotated. The resolution on the iPhone 4S is 852×640, for example.

The blue rectangle is just a live preview for debugging and it’s aspect ratio is the same as 640×480. The live preview could get very slow due to Core Image being very slow.

What I want to do is convert whatever is in the green rectangle to a 640x480 image. Notice the 852x640 is a slightly different aspect ratio than 640x480 too, but that isn’t a huge problem.

  • 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-13T10:11:26+00:00Added an answer on June 13, 2026 at 10:11 am

    Is your goal is to obtain just the exact copy of what you are editing, but with the size of the original image?
    I guess it could be obtained by something like this:

    - (UIImage *)padImage:(UIImage *)img to:(CGSize)size
    {
        if (size.width < img.size.width && size.height < img.size.height) return img;
    
        size.width = MAX(size.width, img.size.width);
        size.height = MAX(size.height, img.size.height);
    
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        CGContextRef context = CGBitmapContextCreate(NULL, size.width, size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
    
        CGRect centeredRect = CGRectMake((size.width - img.size.width)/2.0, (size.height - img.size.height)/2.0, img.size.width, img.size.height);
        CGContextDrawImage(context, centeredRect, [img CGImage]);
    
        CGImageRef imageRef = CGBitmapContextCreateImage(context);
    
        CGColorSpaceRelease(colorSpace);
        CGContextRelease(context);
    
        UIImage *paddedImage = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);
        return paddedImage;
    }
    
    // final image size must be 640x480
    - (void)generateFinalImage
    {
        float rotatableCanvasWidth = 495.0;
        float rotatableCanvasHeight = 320.0;
        UIImage *tmp = self.importedRawImage;
    
        CGSize size = self.importedRawImage.size;
        NSLog(NSStringFromCGSize(size));
    
        tmp = [self padImage:tmp to:CGSizeMake(rotatableCanvasWidth, rotatableCanvasHeight)];
        CIImage *ciImage = [[CIImage alloc] initWithImage:[tmp imageWithTransform:self.importedImageView.transform]];
    
        CGPoint center = CGPointMake(size.width / 2.0, size.height / 2.0);
    
        CIContext *context = [CIContext contextWithOptions:nil];
        CGRect r = ciImage.extent;
        r.origin.x = (r.size.width - rotatableCanvasHeight) / 2.0;
        r.origin.y = (r.size.height - rotatableCanvasWidth) / 2.0;
        r.size.width = rotatableCanvasHeight;
        r.size.height = rotatableCanvasWidth;
        self.finalImage = [UIImage imageWithCGImage:[context createCGImage:ciImage fromRect:r] scale:1.0 orientation:UIImageOrientationUp];
    
        self.finalImage = [self.finalImage resizedImage:CGSizeMake(100.0f, 134.0f) interpolationQuality:kCGInterpolationHigh];
    
        self.previewImageView.image = self.finalImage;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on Rails 3.1 Jquery Ajax demo app listed here https://github.com/samnang/ajax_rails31_demo .
I downloaded the MGSplitViewController project here: https://github.com/mattgemmell/MGSplitViewController and the bindings here: https://github.com/mono/monotouch-bindings/tree/master/MGSplitViewController Where do
I have a demo app which is supposed to be an example of creating
I have got a demo script that lets me authorize with my app and
I have the Demo Table which I can click on the cell(td tag) and
I have one demo application to check select for update query public class Test
Its too much code to paste here so, I have created demo please have
I am using older JQuery Autocomplete plug-in (the one shown here - http://view.jquery.com/trunk/plugins/autocomplete/demo/ ).
I have a web app can be installed on lots of domains and paths.
Hope you can have a quick look at what I'm doing here. Essentially, am

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.