---
title: "图片抗锯齿处理方法"
author: "啸笑天"
date: "2016-03-03T14:06:49Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2016-03-03T14:06:49Z"
id: 2280243
url: "https://justsee.iteye.com/blog/2280243"
---

一、

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

 

二、

 对单个 Layer 开启抗锯齿的方法, imageView.layer.allowsEdgeAntialiasing = YES;  //&gt;=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();
    
    return antiImage;
}
```

 缺点是显示出来会比原来小那么一点点(我的做法是直接cut掉1px的边 当然你也可以直接在图像外面加1px的透明边)

 

我测试了下，二三方法在xcode7，ios9.2效果基本一样。

 

参考：

http://adad184.com/2015/08/31/image-rotate-with-antialiasing/