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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:16:33+00:00 2026-05-26T05:16:33+00:00

I have a UIImageView (initialized with Aspect Fill) inside a UIScrollView. The user shall

  • 0

I have a UIImageView (initialized with Aspect Fill) inside a UIScrollView.
The user shall use that to resize and position a UIImage to his like, press a button and then exactly what he sees on screen would be sent to a server, only in the original image coordinates. In other words, the resulting image would be bigger than the image on screen.

Here’s the essential part of my code so far:

// select the original 
CGFloat imageRatio = self.imageView.image.size.width / self.imageView.image.size.height;    
CGFloat viewRatio  = self.imageView.frame.size.width / self.imageView.frame.size.height;
CGFloat scale;

// get the scale factor of the image being "aspect-filled"
if(imageRatio < viewRatio) {
    scale = self.imageView.image.size.width / self.imageView.frame.size.width;
} else {
    scale = self.imageView.image.size.height / self.imageView.frame.size.height;
}

// get the cropping origin in the image's original coordinates
CGFloat originX = self.imageScrollView.contentOffset.x * scale;
CGFloat originY = self.imageScrollView.contentOffset.y * scale;
CGPoint origin = CGPointMake(originX, originY);

// get the cropping size in the image's original coordinates
CGFloat width  = self.imageView.image.size.width  / self.imageScrollView.zoomScale;
CGFloat height = self.imageView.image.size.height / self.imageScrollView.zoomScale;
CGSize size = CGSizeMake(width, height);

// create the new image from the original one
CGRect imageRect = CGRectMake(origin.x, origin.y, size.width, size.height);
struct CGImage *croppedCGImage = CGImageCreateWithImageInRect(self.imageView.image.CGImage, imageRect);

It already looks quite close to what I want. The origin calculation at least seems correct. However, there is still some difference in the resulting image, which I guess comes from the different aspect ratios of the possible images. Probably I need to add scale to my size equations somehow, but I seriously just can’t wrap my head around how.

Hopefully somebody can help me get this last two meters…

[EDIT]

According to the first comment, I tried out the following. But somehow my targetFrame is always identical to scrollFrame. Is it simply too late at night for me to get something right??

CGFloat zoom = self.imageScrollView.zoomScale;
// the full image resolution
CGRect fullImageFrame = CGRectMake(0, 0,
                                   self.imageView.image.size.width,
                                   self.imageView.image.size.height);
UIView *fullImageView = [[[UIView alloc] initWithFrame:fullImageFrame] autorelease];
// the theoretical size of the image on the screen
CGRect previewImageFrame = CGRectMake(0, 0,
                                      self.imageView.frame.size.width * zoom,
                                      self.imageView.frame.size.height * zoom);
UIView *previewImageView = [[[UIView alloc] initWithFrame:previewImageFrame] autorelease];
// the excerpt of previewImageFrame really visible
CGRect scrollFrame = CGRectMake(self.imageScrollView.contentOffset.x,
                                self.imageScrollView.contentOffset.y,
                                self.imageScrollView.frame.size.width,
                                self.imageScrollView.frame.size.height);
// that excerpt transferred to the full resolution image's coordinates
CGRect targetFrame = [fullImageView convertRect:scrollFrame fromView:previewImageView];
  • 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-26T05:16:34+00:00Added an answer on May 26, 2026 at 5:16 am

    You may wish to explore:

    (CGRect)convertRect:(CGRect)rect toView:(UIView *)view
    

    This and other similar methods allow you to take a view and adjust its coordinate system based on placement in a superview other than the one it was initially intended or positioned for.

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

Sidebar

Related Questions

I have a UIImageView inside of my UIViewController. It loads an image that is
I have one UIImageView that I use to display different images at different points
in my app i have UIImageView inside UIScrollview which i can zoom in and
I have a UIImageView that has a UIImage (obviously), and I want to get
I have a UIImageView object that when clicked it will play a animation, I
I have two UIImageView objects inside my view (both 320x480 one above the other).
I have a UIImageView showing a image that is larger than it's frame. It's
I have a UIImageView that starts off with an image (loading.png) specified in IB.
I have a UIImageView that is displaying a series of pictures as an animation.
I have a UIImageView, and a referencing outlet. However, altough I've set User Interaction

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.