菜鸟教程小白 发表于 2022-12-12 14:32:36

ios - bezierPathWithRoundedRect : gives bad result on retina screen


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

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

<pre><code>-(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;
;

imageView.image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
}
</code></pre>

<p>非常感谢您的帮助!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>问题在于您如何定义图像上下文。您指定的是 1.0 比例,但在视网膜屏幕上应该是 2.0。</p>

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

<pre><code>UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0);
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - bezierPathWithRoundedRect : gives bad result on retina screen,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18760310/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18760310/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - bezierPathWithRoundedRect : gives bad result on retina screen