Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Self-Destructing Message iPhone App Capturing Photo and Video Using UIImagePickerController Resizing an Image and Getting Ready to Send

Stone Preston
Stone Preston
42,016 Points

error in resize image helper method

Ben Jakuben I was going back through the image picker section of the course and noticed a small error in the resize image helper method. currently the video shows the method as:

- (UIImage *)resizeImage:(UIImage *)image toWidth:(float)width andHeight:(float)height {

    CGSize size = CGSizeMake(width, height);
    CGRect rectangle = CGRectMake(0, 0, width, height);
    UIGraphicsBeginImageContext(size);
    //resizes the image property of the view controller
    [self.image drawInRect:rectangle];
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return resizedImage;

}

which resizes the image property of the view controller. But it looks like the method is designed to take an image as an argument, and resize that.

- (UIImage *)resizeImage:(UIImage *)image toWidth:(float)width andHeight:(float)height {

    CGSize size = CGSizeMake(width, height);
    CGRect rectangle = CGRectMake(0, 0, width, height);
    UIGraphicsBeginImageContext(size);
    //resize the image passed in as an argument, not the image property.
    [image drawInRect:rectangle];
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return resizedImage;

}

3 Answers

Good eye!

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Ack! Great catch! Thanks for sharing. Adding a note and lower third now...

Val Singhal
Val Singhal
80 Points

Hi guys, I have a follow up question to this - This is resizing the image on the send side of this app. What about on the receiving side? Will the image be cropped if sending from larger screen size and received on a smaller screen size (sent from iphone 6 -> iphone 4)? Would we simply write a similar method for the ImageViewController to prevent that?

Any clarification would be great.