OGeek|极客世界-中国程序员成长平台

标题: ios - bezierPathWithRoundedRect : gives bad result on retina screen [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:32
标题: ios - bezierPathWithRoundedRect : gives bad result on retina screen

我使用一种方法在我的 iOS 应用程序上获取圆形图片,该方法在 iphone 3 上运行良好。我的问题是,一旦我在 iphone 4 或更高版本上尝试,图片质量很差。

有什么办法,我可以把我的代码转过来获得高分辨率的圆形图片吗?

-(void) setRoundedViewUIImageView *)imageView picture: (UIImage *)picture toDiameterfloat)newSize{

UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);

[[UIBezierPath bezierPathWithRoundedRect:imageView.bounds
                            cornerRadius:100.0] addClip];

CGRect frame=imageView.bounds;
frame.size.width=newSize;
frame.size.height=newSize;
[picture drawInRect:frame];

imageView.image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
}

非常感谢您的帮助!



Best Answer-推荐答案


问题在于您如何定义图像上下文。您指定的是 1.0 比例,但在视网膜屏幕上应该是 2.0。

相反,您可以使用 0.0 来默认为原生质量:

UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0);

关于ios - bezierPathWithRoundedRect : gives bad result on retina screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18760310/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4