Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any code/library to scale down an UIImage?

Is there any code or library out there that can help me scale down an image? If you take a picture with the iPhone, it is something like 2000x1000 pixels which is not very network friendly. I want to scale it down to say 480x320. Any hints?

like image 223
erotsppa Avatar asked Dec 30 '22 13:12

erotsppa


1 Answers

This is what I am using. Works well. I'll definitely be watching this question to see if anyone has anything better/faster. I just added the below to a category on UIimage.

+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize {
  UIGraphicsBeginImageContext( newSize );
  [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
  UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

  return newImage;
}
like image 170
mmc Avatar answered Jan 10 '23 05:01

mmc