美文网首页
ios object-c UIImage图片缩放

ios object-c UIImage图片缩放

作者: codingriver | 来源:发表于2017-11-21 18:24 被阅读312次
    1.等比缩放
    
    
    - (UIImage *) scaleImage:(UIImage *)image toScale:(float)scaleSize {
    UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize);
    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
    }
    
    2.自定义大小
    - (UIImage *) reSizeImage:(UIImage *)image toSize:(CGSize)reSize {
    UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
    [image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
    UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return reSizeImage;
    }
    

    相关文章

      网友评论

          本文标题:ios object-c UIImage图片缩放

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