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
Willie Oeschger
3,776 PointsRibbit App image Resize
Hi I am having trouble with my app were i am getting a error and I do not know why. Please could you help with my code?
- (UIImage *) resizeImage:(UIImage *)image toWidth:(float)width andHight:(float)height
{
CGSize *newSize = CGSizeMake(width, height);
CGRect *newRectangle = CGRectMake(0, 0, width, height);
UIGraphicsBeginImageContext(newSize);
[self.image drawInRect:newRectangle];
UIImage *resizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resizeImage;
}
2 Answers
Ryan Ackermann
2,831 PointsThere is no reason to make pointers to new instances of a CGSize and CGRect. Just simply pass the creation code of the CGSize and CGRect directly in the call.
- (UIImage *) resizeImage:(UIImage *)image toWidth:(float)width andHight:(float)height
{
UIGraphicsBeginImageContext(CGSizeMake(width, height));
[image drawInRect:CGRectMake(0, 0, width, height)];
UIImage *resizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resizeImage;
}
Hope that helps! :)
Willie Oeschger
3,776 PointsThanks dude that worked great!!
Willie Oeschger
3,776 PointsWillie Oeschger
3,776 PointsThe error i am getting is "Initializing 'CGRect *' (aka 'struct CGRect *') with an expression of incompatible type 'CGRect' (aka 'struct CGRect')"