美文网首页
iOS 给一张UIImage指定想要的大小,返回自己需要大小的U

iOS 给一张UIImage指定想要的大小,返回自己需要大小的U

作者: 恋空K | 来源:发表于2019-07-12 13:59 被阅读0次

给原图指定需要的大小,返回自己需要的尺寸大小的图片

+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize {

    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);

    [imagedrawInRect:CGRectMake(0,0, newSize.width, newSize.height)];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnnewImage;

}

此方法不会让图片变得模糊,如果指定的大小比图片本身的大小要小,也不会造成图片缺失,只是按比例把图片缩小到自己想要的大小

相关文章

网友评论

      本文标题:iOS 给一张UIImage指定想要的大小,返回自己需要大小的U

      本文链接:https://www.haomeiwen.com/subject/tnmekctx.html