我正在尝试使用UIImage
的drawInRect:
方法绘制图像。这是代码:
UIImage *image = [UIImage imageNamed:@"OrangeBadge.png"];
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
问题在于生成的图像模糊。以下是源图像(左侧)和生成的图像(右侧)的比较:
我尝试了 CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), NO)
和 CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), NO)
,但这并没有解决问题。
有什么想法吗?
先感谢您。
==
来检查浮点数的相等性。你只需要将比例设置为0.f
,框架就会处理剩下的部分。(参见https://dev59.com/UXE85IYBdhLWcg3wdDSz) - Mazyodif ([UIScreen instancesRespondToSelector:@selector(scale)])
-- 这行代码用于支持 iOS3 吗?scale
属性是从 iOS 4.0 开始支持的。 - tonytony0.0f
将使框架处理正确的比例,无论当前设备是视网膜屏幕还是非视网膜屏幕? - Timo[UIScreen mainScreen].scale
代替硬编码的@2x
,因为iPhone 6+的比例是3x。 - nemesis