zoukankan      html  css  js  c++  java
  • ios 将图片变成圆形

    #pragma mark - 将图片转换成圆形

    -(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {

        UIGraphicsBeginImageContext(image.size);

        CGContextRef context = UIGraphicsGetCurrentContext();

        CGContextSetLineWidth(context, 2);

        CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);

        CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);

        CGContextAddEllipseInRect(context, rect);

        CGContextClip(context);

        

        [image drawInRect:rect];

        CGContextAddEllipseInRect(context, rect);

        CGContextStrokePath(context);

        UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return newimg;

    }

    上面代码注意 如果裁剪后没有使用 CGContextAddEllipseInRect(context, rect);
    CGContextStrokePath(context); 这条代码 就会引起背景为白色时看不出来任务效果。
    这里是椭圆操作

    握不住的沙,干脆扬了它。
  • 相关阅读:
    Java内存区域
    spring学习之Bean
    记一次日本公司的Java面试
    java中打印输出数组内容的三种方式
    Java创建子类时构造器执行顺序
    转发&重定向
    Java继承
    GXOI&GZOI
    LCT能干啥???
    后缀自动机的一些应用
  • 原文地址:https://www.cnblogs.com/zj901203/p/4271929.html
Copyright © 2011-2022 走看看