zoukankan      html  css  js  c++  java
  • 如何高性能的给UIImageView加个圆角?(不准说layer.cornerRadius!)

    豆电雨 搬砖自味精:http://awhisper.github.io/2016/03/12/滚动圆角卡顿刨根问底/

     使用Quartz2D直接绘制图片

    步骤: 
      a、创建目标大小(cropWidth,cropHeight)的画布。

      b、使用UIImage的drawInRect方法进行绘制的时候,指定rect为(-x,-y,width,height)。

      c、从画布中得到裁剪后的图像。

    - (UIImage*)cropImageWithRect:(CGRect)cropRect
    {
      //豆电雨 CGRect drawRect
    = CGRectMake(-cropRect.origin.x , -cropRect.origin.y, self.size.width * self.scale, self.size.height * self.scale); UIGraphicsBeginImageContext(cropRect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClearRect(context, CGRectMake(0, 0, cropRect.size.width, cropRect.size.height)); [self drawInRect:drawRect]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } @end
  • 相关阅读:
    js 笔记
    openstack笔记
    Nginx
    Nginx
    Nginx
    nginx 服务器篇
    Nginx 原理篇
    MySQL 视图、触发器、函数、存储过程
    day41
    MySQL 作业题及答案
  • 原文地址:https://www.cnblogs.com/starainDou/p/5289408.html
Copyright © 2011-2022 走看看