zoukankan      html  css  js  c++  java
  • iOS给一张矩形图片剪切成圆形图片

    随着APP发展,个人账户的注册和登陆,都有头像的设置,圆形头像也越来越多,此方法正是对剪切圆头像的封装。 
     
     
    //****************************************************************************************************************//
    //****************************************************************************************************************//

    //*********************************************图片剪切成圆形********************************************************//

    //****************************************************************************************************************//

    //**********************************************************************笨笨编程************************************//

    //****************************************************************************************************************//

    /**

     * parm:sourceImage:需要剪切的原图片

     * parm:borderWidth:剪切后的边框宽度

     * parm:borderColor:边框颜色

     */

    - (UIImage *)circleImageWithImage:(UIImage *)sourceImage borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor{

        CGFloat imageWidth = sourceImage.size.width + 2 * borderWidth;

        CGFloat imageHeight = sourceImage.size.height + 2 * borderWidth;

        UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageWidth, imageHeight), NO, 0.0);

        UIGraphicsGetCurrentContext();

        CGFloat radius = (sourceImage.size.width < sourceImage.size.height?sourceImage.size.sourceImage.size.height)*0.5;

        UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(imageWidth * 0.5, imageHeight * 0.5) radius:radius startAngle:0 endAngle:M_PI * 2 clockwise:YES];

        bezierPath.lineWidth = borderWidth;

        [borderColor setStroke];

        [bezierPath stroke];

        [bezierPath addClip];

        [sourceImage drawInRect:CGRectMake(borderWidth, borderWidth, sourceImage.size.width, sourceImage.size.height)];

        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();   

        UIGraphicsEndImageContext();    

        return image;

    }

  • 相关阅读:
    从TCP三次握手说起——浅析TCP协议中的疑难杂症
    动态绑定是如何实现的?
    C++对象的内存模型
    C/C++关键字
    libevent库介绍--事件和数据缓冲
    libevent编程疑难解答
    大型工程多个目录下的Makefile写法
    C++中的RAII机制
    C++中的智能指针
    二叉树的非递归遍历
  • 原文地址:https://www.cnblogs.com/chenjie-ios/p/4661683.html
Copyright © 2011-2022 走看看