我的旋转图像没有锐边
-
07-07-2019 - |
题
我使用以下代码旋转图像:
CGAffineTransform rotate = CGAffineTransformMakeRotation( [ratio floatValue] );
[imageView setTransform:rotate];
但它没有尖锐的边缘,有人知道解决方案吗?
这是我得到的图像:
其他提示
使用UIImageView的CALayer对图像进行栅格化将提供最佳的抗锯齿效果。
imageView.layer.shouldRasterize = YES;
只需为图片添加1px透明边框
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContext( imageRect.size );
[image drawInRect:CGRectMake(1,1,image.size.width-2,image.size.height-2)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
任何时候你对图像进行变换(90°增量除外)都会因像素插值而导致边缘稍微柔和。
您可以在Info.plist中设置一个启用边缘抗锯齿的键:UIViewEdgeAntialiasing。
最简单的解决方案:
只需将此键值对添加到Info.plist: UIViewEdgeAntialiasing设置为YES。
不隶属于 StackOverflow