zoukankan      html  css  js  c++  java
  • IOS图片调整用法bitmap

    学习链接:https://www.jianshu.com/p/8f508f4ffd2c

    直接上代码吧

    //将image图片转化为符合要求的图片

    - (UIImage *)transformImage:(UIImage *)image WithTargetRect:(CGRect) targetRect {

        //将image改为50 * 50pt大小的

        CGSize smallImageSize = CGSizeMake(50.0f, 50.0f);

        //创建一个目标大小的画板

        UIGraphicsBeginImageContextWithOptions(smallImageSize, NO, [[UIScreen mainScreen] scale]);

        //将需要转换的图片画在上面

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

        //保存下来

        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();

        //结束画板

        UIGraphicsEndImageContext();

        

        //创建一个纯色图片

        UIColor *backgroudColor =[UIColor whiteColor];

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

        CGContextRef context = UIGraphicsGetCurrentContext();

        

        //设置圆角

        float radius = 8.0f;

        CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:targetRect cornerRadius:radius].CGPath);

        CGContextClip(context);

        

        CGContextSetFillColorWithColor(context, [backgroudColor CGColor]);//填充

        CGContextFillRect(context, targetRect);

        //将smallImage画到纯色背景上

        CGFloat margin = 4.0f;

        [smallImage drawAtPoint:CGPointMake(margin, margin)];

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        

        return newImage;

    }

  • 相关阅读:
    URL记录
    Mongodb集群节点故障恢复场景分析(转)
    IO 和 NIO 的区别
    VUE 前端项目优化方法
    缓存的穿透和雪崩
    接口如何处理重复请求?
    线程池构造类 ThreadPoolExecutor 的 5 个参数
    大型网站在架构上应当考虑哪些问题
    synchronized 和 lock 的区别
    JVM虚拟机 YGC和FGC发生的具体场景
  • 原文地址:https://www.cnblogs.com/caijiaming/p/14024272.html
Copyright © 2011-2022 走看看