UIImageView绘制圆形图片
来源:互联网 发布:angularjs.min.js 编辑:程序博客网 时间:2024/04/29 20:51
参考网上的资料,自实现了一个UIImageView绘制圆形图片功能。
先看效果:
代码如下:
- (void)buttonAction:(id)sender {
//方式1,见上图的方式1效果。通过imageview的layer来操作
UIImageView *imageView1 = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"11.png"]];
imageView1.frame = CGRectMake(60,100,100, 100);
imageView1.layer.masksToBounds =YES;
imageView1.layer.cornerRadius =50;
[self.view addSubview:imageView1];
//方式2,见上图的方式2效果。对画布裁剪成圆形,然后再将原始图像画出来
UIImageView *imageView2 = [[UIImageViewalloc]initWithFrame:CGRectMake(60,250,100,100)];
UIImage *image2 = [UIImageimageNamed:@"12.png"];
imageView2.image = [selfcircleImage:image2withParam:0];
[self.view addSubview:imageView2];
}
-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {
UIGraphicsBeginImageContext(image.size);
CGContextRef context =UIGraphicsGetCurrentContext();
//圆的边框宽度为2,颜色为红色
CGContextSetLineWidth(context,2);
CGContextSetStrokeColorWithColor(context, [UIColorredColor].CGColor);
CGRect rect = CGRectMake(inset, inset, image.size.width - inset *2.0f, image.size.height - inset *2.0f);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context);
//在圆区域内画出image原图
[image drawInRect:rect];
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
//生成新的image
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}
- UIImageView绘制圆形图片
- iOS—UIImageView绘制圆形图片
- Android_绘制圆形图片
- android 绘制圆形图片
- 绘制圆形图片
- Android 绘制圆形图片
- 绘制圆形图片
- BitmapShader绘制圆形图片
- 圆形图片绘制
- IOS绘制圆形图片
- Android 绘制圆形图片
- 绘制圆形图片:登陆头像
- 安卓绘制圆形图片
- 绘制圆形头像或图片
- UIImageView 圆形
- 将矩形图片绘制成圆形图片
- Qt 绘制圆形图片去除锯齿 圆形图片
- iOS开发 Xcode UIImageView设置一个圆形的图片
- 音视频同步-时间戳
- BUPT Spring Ranking Contest For 13 Round #4 graph
- ubuntu android no permission
- Cxgrid根据列条件改变行颜色
- 基于Ajax和Java反射机制的RPC实现:轻量高效的解决前后端交互
- UIImageView绘制圆形图片
- Android ListView某几行加上标签(类似微信联系人界面显示)
- ios 隐藏状态栏
- Class文件格式总结
- 剑指offer面试题27
- Android SQLite的数据库文件存储在SD卡中(一)
- android个推平台
- Horn框架笔记|基础配置
- SSL与TLS区别及介绍