zoukankan      html  css  js  c++  java
  • 图片裁剪成圆形(无边框)

    /**

     *  图片裁剪成圆形(无边框)

     */

    - (UIImage *)imageWithCornerRadius:(CGFloat)radius {

        

        CGFloat sideLength = MAX(self.size.width, self.size.height);

        CGRect rect = (CGRect){0.f, 0.f, sideLength, sideLength};

        

        UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);

        CGContextAddPath(UIGraphicsGetCurrentContext(),

                         [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:sideLength * 0.5].CGPath);

        CGContextClip(UIGraphicsGetCurrentContext());

        

        CGFloat imgX = (sideLength - self.size.width) * 0.5;

        CGFloat imgY = (sideLength - self.size.height) * 0.5;

        CGRect imgRect = (CGRect){imgX, imgY, self.size};

        

        [self drawInRect:imgRect];

        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

        

        UIGraphicsEndImageContext();

        return image;

    }

  • 相关阅读:
    Xn数列(codevs 1281)
    素数密度(洛谷 1835)
    Sightseeing(poj 3463)
    线段树——Ultra-QuickSort
    最大子矩阵
    完成作业的先后顺序
    堆积木块的最大高度
    最长上升序列和
    最长上升子序列
    高精度乘法程序
  • 原文地址:https://www.cnblogs.com/chenzq12/p/6213715.html
Copyright © 2011-2022 走看看