Any code/library to scale down an UIImage?

后端 未结 4 462
北荒
北荒 2021-01-01 04:43

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 n

4条回答
  •  萌比男神i
    2021-01-01 05:03

    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;
    }
    

提交回复
热议问题