图片抗锯齿处理方法

本文介绍了三种在iOS中实现图片抗锯齿的方法:1) 在Info.plist中设置UIViewEdgeAntialiasing为YES,但可能影响性能;2) 对单个Layer开启抗锯齿,如imageView.layer.allowsEdgeAntialiasing = YES;3) 使用Category处理,但可能导致图片缩小。在iOS 9.2及Xcode 7上,方法二和三效果接近。参考链接提供相关Demo。
摘要由CSDN通过智能技术生成

一、

这个简单的键-值对添加到您的Info.plist:UIViewEdgeAntialiasing设置为YES。但是这样容易出现性能问题。

 

二、

 对单个 Layer 开启抗锯齿的方法, imageView.layer.allowsEdgeAntialiasing = YES;  //>=ios7

 

三、

image的category

- (UIImage *)antiAlias
{
    CGFloat border = 1.0f;
    CGRect rect = CGRectMake(border, border, self.size.width-2*border, self.size.height-2*border);
	
    UIImage *img = nil;
    
    UIGraphicsBeginImageContext(CGSizeMake(rect.size.width,rect.size.height));
    [self drawInRect:CGRectMake(-1, -1, self.size.width, self.size.height)];
    img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    UIGraphicsBeginImageContext(self.size);
    [img drawInRect:rect];
    UIImage* antiImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值