本文主要是介绍UIImage 绘制椭圆,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- UIImage * srcImg =[UIImage imageNamed:@"abc.png"];
- CGFloat width = srcImg.size.width;
- CGFloat height = srcImg.size.height;
- //开始绘制图片
- UIGraphicsBeginImageContext(srcImg.size);
- CGContextRef gc = UIGraphicsGetCurrentContext();
- 绘制Clip区域
- CGContextAddEllipseInRect(gc, CGRectMake(0, 0,100, 75)); //椭圆
- CGContextClosePath(gc);
- CGContextClip(gc);
- //坐标系转换
- //因为CGContextDrawImage会使用Quartz内的以左下角为(0,0)的坐标系
- CGContextTranslateCTM(gc, 0, height);
- CGContextScaleCTM(gc, 1, -1);
- CGContextDrawImage(gc, CGRectMake(0, 0, width, height), [srcImg CGImage]);
- //结束绘画
- UIImage *destImg = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- UIImageView * view =[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
- [view setImage:destImg];
- [self.view addSubview:view];
这篇关于UIImage 绘制椭圆的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!