【问题标题】:bezierPathWithRoundedRect: gives bad result on retina screenbezierPathWithRoundedRect:在视网膜屏幕上给出不好的结果
【发布时间】:2023-09-02 16:01:01
【问题描述】:

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

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

-(void) setRoundedView:(UIImageView *)imageView picture: (UIImage *)picture toDiameter:(float)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();
}

非常感谢您的帮助!

【问题讨论】:

    标签: ios uiimageview uiimage rounding uibezierpath


    【解决方案1】:

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

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

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

    【讨论】:

      最近更新 更多