美文网首页
Image剪裁到指定尺寸

Image剪裁到指定尺寸

作者: 起名好难_fz | 来源:发表于2016-12-15 15:36 被阅读10次

    - (UIImage *)clipImage:(UIImage *)image toSize:(CGSize)size {

    UIGraphicsBeginImageContextWithOptions(size, YES, [UIScreen mainScreen].scale);

    CGSize imgSize = image.size;

    CGFloat x = MAX(size.width / imgSize.width, size.height / imgSize.height);

    CGSize resultSize = CGSizeMake(x * imgSize.width, x * imgSize.height);

    [image drawInRect:CGRectMake(0, 0, resultSize.width, resultSize.height)];

    UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return finalImage;

    }

    相关文章

      网友评论

          本文标题:Image剪裁到指定尺寸

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