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

  • Home
  • SEARCH
  • 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 6044137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:58:40+00:00 2026-05-23T06:58:40+00:00

basically I am making an app that involves a user taking a photo, or

  • 0

basically I am making an app that involves a user taking a photo, or selecting one already on their device, and then placing an overlay onto the image.

So, I seem to have coded everything fine, apart from one thing, after the user has selected the overlay and positioned it, when saved the size of the overlay has changed, whereas the x and y values seem correct.

And so this is the code I use to add the overlay (“image” being the users photo):

float wid = (overlay.image.size.width);
float hei = (overlay.image.size.height);

overlay.frame = CGRectMake(0, 0, wid, hei);
[image addSubview:overlay];

And this is the code used to save the resulting image:

UIGraphicsBeginImageContext(image.image.size);  

// Draw the users photo  
[image.image drawInRect:CGRectMake(0, 0, image.image.size.width, image.image.size.height)];  

// Draw the overlay  
float xx = (overlay.center.x);
float yy = (overlay.center.y);

CGRect aaFrame = overlay.frame;
float width = aaFrame.size.width;
float height = aaFrame.size.height;


[overlay.image drawInRect:CGRectMake(xx, yy, width, height)];
    UIGraphicsEndImageContext();

Any help? Thanks

  • 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-23T06:58:41+00:00Added an answer on May 23, 2026 at 6:58 am

    The problem is that you are using image’s size rather than the image view’s frame size. Image seems to be much larger than its image view so when you use the image’s size the other image’s size ends up being much smaller in comparison although it is still the correct size. You can modify your snippet to this –

    UIGraphicsBeginImageContext(image.frame.size);  
    
    // Draw the users photo  
    [image.image drawInRect:CGRectMake(0, 0, image.frame.size.width, image.frame.size.height)];  
    [overlay.image drawInRect:overlay.frame];
    
    UIImage * resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    

    Avoiding loss of quality

    While the above method leads to loss of resolution, trying to draw the parent image in its proper resolution might have an unwanted effect on its child image i.e. if the overlay wasn’t of high resolution itself then it can end being stretchy. However you can try this code to draw it in the parent image’s resolution (untested, let me know if you’ve problems ) –

    float verticalScale = image.image.size.height / image.frame.size.height;
    float horizontalScale = image.image.size.width / image.frame.size.width;
    
    CGRect overlayFrame = overlay.frame;
    overlayFrame.origin.x *= horizontalScale;
    overlayFrame.origin.y *= verticalScale;
    overlayFrame.size.width *= horizontalScale;
    overlayFrame.size.height *= verticalScale;
    
    UIGraphicsBeginImageContext(image.image.size);  
    
    // Draw the users photo  
    [image.image drawInRect:CGRectMake(0, 0, image.image.size.width, image.image.size.height)];  
    [overlay.image drawInRect:overlayFrame];
    
    UIImage * resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm basically making an app that adds a count to a number and
I am currently making an app that will have multiple timers, which are basically
I am making an app which basically presents data (from plist) to user in
I'm making a Stored Procedure that basically concatenates a long string with data from
Long story short, I'm making a custom Swing component that's basically a JTable with
I'm making a shopping list app which basically uploads your shopping list to a
I'm making Android app that has this database in it: public void onCreate(SQLiteDatabase db)
i m making an iphone app that displays data from a website on a
I am making an iPhone app that enables users to search for a city/town/countries/states
This one is a tough one... I've got a C# app that runs an

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.