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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:18:57+00:00 2026-05-28T05:18:57+00:00

i am trying to scale down a image i get from photo library on

  • 0

i am trying to scale down a image i get from photo library on touchesmoved by user in a similar way like when we take picture with camera using UIImagepicker setEditing to Yes method(or like the camera app).

I am trying to use the following method passing in some parameters based on touchesmoved but i am not getting the desired effect? what am i possibly doing wrong??

-(UIImage*)scaleToSize:(UIImage *)img:(CGSize)size
{


// Create a bitmap graphics context
    // This will also set it as the current context
    UIGraphicsBeginImageContext(size);

// Draw the scaled image in the current context
[img drawInRect:CGRectMake(0, 0, size.width, size.height)];

// Create a new image from current context
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();

// Pop the current context from the stack
UIGraphicsEndImageContext();

// Return our new scaled image
return scaledImage;
}

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UIImage *img = [self scaleToSize:imgView.image:CGSizeMake(touch1.x,touch1.y)];
        imgView.image=img;
}

also how can i save the scaled image once somehow i scale it??

  • 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-28T05:18:58+00:00Added an answer on May 28, 2026 at 5:18 am

    Building on your comment, the image will distort as it will draw the image into the rectangle specified and if the new dimensions are not the same aspect ratio (the width / height) as the original image then it will appear distorted.

    You need some logic to ensure that your new width and height have the same aspect ratio, for example:

    CGFloat newHeight = imageView.frame.size.height * size.width / imageView.frame.size.width;
    

    If you make your Graphics context size.width and newHeight and then draw your image into this rect it will maintain the aspect ratio.

    You will likely want to put some extra logic in there to either create a new width given the height or new height given the width, depending on which dimension was the largest change.

    Hope this helps,

    Dave

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

Sidebar

Related Questions

I'm trying to scale an image down, change the image, then scale it back
I'm trying to get every widget to scale with change in window size. I
I have this picture, represented in red on the following image. I am trying
I'm trying to scale down a Bitmap using GDI+ by doing the following: Bitmap
Trying to track down an bad image replacement error. An image of a different
i'm trying to get a full screen trail effect similar to the one here:
I am trying to scale an ImageView down in an animation, but whenever I
I'm trying to get started with Scala and cannot get out of the starting
Because regular expressions scare me, I'm trying to find a way to remove all
I'm trying to get a real equivalent for Java's public static final in Scala

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.