美文网首页
图片截取

图片截取

作者: BlueSky520 | 来源:发表于2016-11-10 17:07 被阅读0次

    - (UIImage *)cutImage:(UIImage*)image

    {

    //压缩图片

    CGSize newSize;

    CGImageRef imageRef = nil;

    if ((image.size.width / image.size.height) < (_model.listImageWidth / _model.listImageWidth)) {

    newSize.width = image.size.width;

    newSize.height = image.size.width * _model.listImageWidth / _model.listImageWidth;

    imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(0, fabs(image.size.height - newSize.height) / 2, newSize.width, newSize.height));

    } else {

    newSize.height = image.size.height;

    newSize.width = image.size.height * _model.listImageWidth / _model.listImageWidth;

    imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(fabs(image.size.width - newSize.width) / 2, 0, newSize.width, newSize.height));

    }

    return [UIImage imageWithCGImage:imageRef];

    }

    相关文章

      网友评论

          本文标题:图片截取

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