• 图片缩小


    //如果图片大于maxSize,将图片高宽等比例缩放至maxSize

    - (UIImage *)imageWithConstrainSize:(CGSize)maxSize

    {

        if(self.size.width <= maxSize.width && self.size.height <= maxSize.height) return self;

        

        CGFloat scale = MAX(maxSize.width/self.size.width, maxSize.height/self.size.height);

        CGSize scaleSize = CGSizeMake(scale * self.size.width,  scale * self.size.height);

        

        UIGraphicsBeginImageContext(scaleSize);

        // 绘制改变大小的图片

        [self drawInRect:CGRectMake(0, 0, scaleSize.width, scaleSize.height)];

        // 从当前context中创建一个改变大小后的图片

        UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();

        // 使当前的context出堆栈

        UIGraphicsEndImageContext();

        // 返回新的改变大小后的图片

        return scaledImage;

    }

  • 相关阅读:
    代码性能优化-1
    sql调优-1
    2020.11.08 字符串可以是对象
    2020.11.09 JavaScript运算符
    2020.11.10 JavaScript 比较
    2020.11.11
    2020.11.12 条件语句
    2020.11.13 switch语句
    2020.11.14 循环
    2020.11.15
  • 原文地址:https://www.cnblogs.com/ldc529/p/3831411.html
Copyright © 2020-2023  润新知