zoukankan      html  css  js  c++  java
  • iOS 利用Context裁剪图片

    下面的代码可以裁剪出圆形的图片,

    1,先把不规则图片转成正方形图片

    UIGraphicsBeginImageContext(newSize);
       
     [image drawInRect:CGRectMake(0,0,newSize.width,newSize.width)];
    
     UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
     UIGraphicsEndImageContext();

    2 ,把正方形图像绘制剪切为圆形

     UIGraphicsBeginImageContext(image.size);
     CGContextRef context = UIGraphicsGetCurrentContext();
    
        
     CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
     CGContextAddEllipseInRect(context, rect);
     CGContextClip(context); //进行剪切,所有context绘制只保留能够被当前path进行fill的区域
     [image drawInRect:rect]; //绘制原图
       
        
     UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();
  • 相关阅读:
    对象拷贝-深拷贝
    eclipse安装桌面快捷方式
    ajax 分页
    单例模式
    过滤器
    ajax参数详解
    json
    反射
    jdbc02
    jdbc --例子7
  • 原文地址:https://www.cnblogs.com/breezemist/p/3539512.html
Copyright © 2011-2022 走看看