//图片会失真
- (UIImage*)originImage:(UIImage*)image scaleToSize:(CGSize)size{
UIGraphicsBeginImageContext(size);//size 为CGSize类型,即你所需要的图片尺寸
[image drawInRect:CGRectMake(0,0, size.width, size.height)];
UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();returnscaledImage;}
//此方法图片不失真
- (UIImage*)originImage:(UIImage *)image scaleToSize:(CGSize)size
{
// 第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
UIGraphicsBeginImageContextWithOptions(size,NO, [UIScreen mainScreen].scale);
[image drawInRect:CGRectMake(0,0, size.width, size.height)];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
returnscaledImage;
}