设置UIImage 圆角
//设置UIImage圆角
@interface UIImage(UIRoundedRectImage)
+ (id) createRoundedRectImage:(UIImage*)image size:(CGSize)size;
@end
@implementation UIImage(UIRoundedRectImage)
static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth,
float ovalHeight)
{
float fw,fh;
if (ovalWidth == 0 || ovalHeight == 0) {
CGContextAddRect(context, rect);
return;
}
CGContextSaveGState(context);
CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM(context, ovalWidth, ovalHeight);
fw = CGRectGetWidth(rect) / ovalWidth;
fh = CGRectGetHeight(rect) / ovalHeight;
CGContextMoveToPoint(context, fw, fh/2); // Start at lower right corner
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // Top right corner
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right
CGContextClosePath(context);
CGContextRestoreGState(context);
}
+ (id) createRoundedRectImage:(UIImage*)image size:(CGSize)size
{
// the size of CGContextRef
int w = size.width;
int h = size.height;
UIImage *img = image;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace,kCGImageAlphaPremultipliedFirst);
CGRect rect = CGRectMake(0, 0, w, h);
CGContextBeginPath(context);
addRoundedRectToPath(context, rect, 5, 5);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
@end
设置UIImage 圆角的更多相关文章
- tableView 获取网络图片,并且设置为圆角(优化,fps)
代码地址如下:http://www.demodashi.com/demo/11088.html 一.准备工作 例子比较精简,没有什么特殊要求,具备Xocde8.0左右版本的就好 二.程序实现 1.相关 ...
- 设置UIImage的渲染模式:UIImage.renderingMode
设置UIImage的渲染模式:UIImage.renderingMode 着色(Tint Color)是iOS7界面中的一个.设置UIImage的渲染模式:UIImage.renderingMode重 ...
- iOS UITabBarItem 选中图的颜色,设置UIimage的渲染模式
UITbarController之前有在这篇文章讲解:http://www.cnblogs.com/niit-soft-518/p/4447940.html 如果自定义了UITabBarItem的图片 ...
- php imagick设置图片圆角的方法
php imagick设置图片圆角的方法 <pre>header('Content-Type: image/png'); $image = new Imagick('http://stat ...
- 设置UICollectionViewCell圆角和阴影
设置cell圆角: cell.contentView.layer.cornerRadius =2.0f; cell.contentView.layer.borderWidth =1.0f; cell. ...
- iOS 中如何将View设置为圆角的矩形?
今天刚好需要添加一个圆角的view. 必须先导入头文件. #import <QuartzCore/QuartzCore.h> bgView.layer.cornerRadius = cor ...
- [转]怎么把一个textview的背景图片设置成圆角的?
在drawable文件夹下新建一个文件设置背景样式代码:在drawable文件夹下面新建text_view_border.xml<?xml version="1.0" ...
- iOS: 使用故事板和xib设置按钮圆角方法
使用storyboard如何设置圆角或边框? 通过storyboard的 运行时属性runtime attribute,可以对Button设置圆角或者边框 1.很多人都知道,通常设置一个 Button ...
- ios中设置UIButton圆角,添加边框
//例如: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(50, ...
随机推荐
- log4j打印日志配置
1.所需的jar包 <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifa ...
- CodeForces485A——Factory(抽屉原理)
Factory One industrial factory is reforming working plan. The director suggested to set a mythical d ...
- 在MAC中安装XMPP服务器
一.安装MySQL 1.下载安装包
- Spring中通配符
一.加载路径中的通配符:?(匹配单个字符),*(匹配除/外任意字符).**/(匹配任意多个目录) classpath:app-Beans.xml 说明:无通配符,必须完全匹配 classpath: ...
- php post和get
作为一个计算机系统,输入输出设备作为非核心设备却是不可或缺的,硬件如此,软件亦是如此.试想一台功能强劲的计算机,如果没有输入输出设备,它与一块只能耗电并且发出嗡嗡噪音的废铁有何不同.应用程序的道理也是 ...
- Vi Usage
标签: linux 编辑工具 md 快捷键以及常用命令(前面带:的是命令) h -> 左移一个字符 j -> 下移一行 k -> 上移一行 l -> 右移一个字符 w或Shif ...
- MYSQL语句中SELECT语句及其子句的执行顺序
SELECT语句的执行的逻辑查询处理步骤:(8)SELECT (9)DISTINCT(11)<TOP_specification> <select_list>(1)FROM & ...
- 感谢大家的支持,发布一个JWFD的补丁文件
请用这个文件覆盖原来的JWFD开发包里面的同名文件,然后删除JWFD目录下面的那个FLOWTREE.OBJ 文件 然后重启JWFD.... 这个补丁修正了 流程图设计器-树型列表的几个BUG,因为有 ...
- No resource found that matches the given name
XML里面明显已经定义了ID,可是android:layout_toLeftOf="@id/text_seller"报错,说没有定义,原来这玩意要写在相对位置对象声明的下面,是有顺 ...
- jQuery 清除div内容
$.ajax({ url: "SearchSN.aspx", data: "SN=" + $("#txtS ...