iOS 利用Context裁剪图片
2014-02-07 14:48
381 查看
下面的代码可以裁剪出圆形的图片,
1,先把不规则图片转成正方形图片
2 ,把正方形图像绘制剪切为圆形
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();
相关文章推荐
- iOS--UIGraphicsBeginImageContext系列知识(图片缩放裁剪、改变大小、合并、裁剪部分、保存到媒体库)
- 一个利用html5的图片裁剪功能(已解决ios压扁缩放等bug)
- iOS图片裁剪
- Java 利用jquery库cropper完成图片裁剪功能
- openCV学习笔记(8):利用cvSetImageROI截取/裁剪图片
- iOS学习笔记-060.图形的基本绘制、图片水印、图片裁剪
- 利用Jquery的cropper插件实现拖动层动态头剪切(裁剪头像)图片
- 利用iOS绘制图片生成随机验证码示例代码
- iOS-图片裁剪
- iOS如何实现图片的不同形状裁剪和添加相框
- IOS学习笔记39——拍照、从相册选图并对图片进行裁剪
- iOS 编程 利用UIScrollView 编写无缝循环显示图片
- iOS 图片裁剪与修改
- 利用Javascript裁剪图片并存储的简单实现
- 利用jquery的imgAreaSelect插件实现图片裁剪示例
- 【iOS开发-55】图片轮播案例:scrollView的分页、滚动条、利用代理控制定时器和Page Control以及多线程问题
- iOS 利用阿里云上传及下载图片
- 利用Quartz 2D实现图片的旋转、缩放、裁剪
- iOS 相机拍照、相册获取照片(仿微信) 一一 从相册获取图片、图片裁剪
- ios 利用 NSURLSession下载图片