文章标题
来源:互联网 发布:手机角度测量软件 编辑:程序博客网 时间:2024/06/05 14:11
高性能的图片圆角
一般初学者很多情况下设置图片圆角都是设置UIImageView的Layer,
UIImageView* imageView = [[UIImageView alloc]init];imageView.layer.cornerRadius = 10.0;imageView.layer.masksToBounds = YES;
但是这回造成离屏渲染耗费性能,下面介绍一种好的处理方式
-(UIImage*)image:(UIImage*)image WithCornerRadius:(CGFloat)radius andSize:(CGSize)size{ CGRect rect = (CGRect){0.f,0.f,size}; UIGraphicsBeginImageContextWithOptions(size, NO, 1.0); //根据矩形画带圆角的曲线 [[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius]addClip]; [image drawInRect:rect]; UIImage * resultImage = UIGraphicsGetImageFromCurrentImageContext(); //关闭上下文 UIGraphicsEndImageContext(); return resultImage;}
这是我封装的工具类里的一个方法,直接拖出去用即可,将需要切割的image、圆角半径已经UIImageView的size大小传进去即可。
1 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- boost学习
- 浅析javaI/O工作机制
- Activity管理器用来增加,移除Activity
- 【STL】 map、set;
- springMVC+velocity配置
- 文章标题
- iOS 自定义加密算法——原理
- Android - ToolBar详解
- terminate called after throwing an instance of 'std::length_error
- 【前端】web安全字体
- Beyond Compare文件比较四种结果分析
- 749 B. Parallelogram is Back codeforces
- 编程实现
- basic use of sidekiq (2)